From: Calvin Wan <calvinwan@google.com>
To: git@vger.kernel.org
Cc: Calvin Wan <calvinwan@google.com>,
emilyshaffer@google.com, avarab@gmail.com,
phillip.wood123@gmail.com
Subject: [PATCH v2 2/4] submodule: move status parsing into function
Date: Tue, 11 Oct 2022 23:26:02 +0000 [thread overview]
Message-ID: <20221011232604.839941-3-calvinwan@google.com> (raw)
In-Reply-To: <https://lore.kernel.org/git/20220922232947.631309-1-calvinwan@google.com/>
A future patch requires the ability to parse the output of git
status --porcelain=2. Move parsing code from is_submodule_modified to
parse_status_porcelain.
Signed-off-by: Calvin Wan <calvinwan@google.com>
---
submodule.c | 71 +++++++++++++++++++++++++++++------------------------
1 file changed, 39 insertions(+), 32 deletions(-)
diff --git a/submodule.c b/submodule.c
index 72b295b87b..a3410ed8f0 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1864,6 +1864,43 @@ int fetch_submodules(struct repository *r,
return spf.result;
}
+static int parse_status_porcelain(char *buf, unsigned *dirty_submodule, int ignore_untracked)
+{
+ /* regular untracked files */
+ if (buf[0] == '?')
+ *dirty_submodule |= DIRTY_SUBMODULE_UNTRACKED;
+
+ if (buf[0] == 'u' ||
+ buf[0] == '1' ||
+ buf[0] == '2') {
+ /* T = line type, XY = status, SSSS = submodule state */
+ if (strlen(buf) < strlen("T XY SSSS"))
+ BUG("invalid status --porcelain=2 line %s",
+ buf);
+
+ if (buf[5] == 'S' && buf[8] == 'U')
+ /* nested untracked file */
+ *dirty_submodule |= DIRTY_SUBMODULE_UNTRACKED;
+
+ if (buf[0] == 'u' ||
+ buf[0] == '2' ||
+ memcmp(buf + 5, "S..U", 4))
+ /* other change */
+ *dirty_submodule |= DIRTY_SUBMODULE_MODIFIED;
+ }
+
+ if ((*dirty_submodule & DIRTY_SUBMODULE_MODIFIED) &&
+ ((*dirty_submodule & DIRTY_SUBMODULE_UNTRACKED) ||
+ ignore_untracked)) {
+ /*
+ * We're not interested in any further information from
+ * the child any more, neither output nor its exit code.
+ */
+ return 1;
+ }
+ return 0;
+}
+
unsigned is_submodule_modified(const char *path, int ignore_untracked)
{
struct child_process cp = CHILD_PROCESS_INIT;
@@ -1900,39 +1937,9 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
fp = xfdopen(cp.out, "r");
while (strbuf_getwholeline(&buf, fp, '\n') != EOF) {
- /* regular untracked files */
- if (buf.buf[0] == '?')
- dirty_submodule |= DIRTY_SUBMODULE_UNTRACKED;
-
- if (buf.buf[0] == 'u' ||
- buf.buf[0] == '1' ||
- buf.buf[0] == '2') {
- /* T = line type, XY = status, SSSS = submodule state */
- if (buf.len < strlen("T XY SSSS"))
- BUG("invalid status --porcelain=2 line %s",
- buf.buf);
-
- if (buf.buf[5] == 'S' && buf.buf[8] == 'U')
- /* nested untracked file */
- dirty_submodule |= DIRTY_SUBMODULE_UNTRACKED;
-
- if (buf.buf[0] == 'u' ||
- buf.buf[0] == '2' ||
- memcmp(buf.buf + 5, "S..U", 4))
- /* other change */
- dirty_submodule |= DIRTY_SUBMODULE_MODIFIED;
- }
-
- if ((dirty_submodule & DIRTY_SUBMODULE_MODIFIED) &&
- ((dirty_submodule & DIRTY_SUBMODULE_UNTRACKED) ||
- ignore_untracked)) {
- /*
- * We're not interested in any further information from
- * the child any more, neither output nor its exit code.
- */
- ignore_cp_exit_code = 1;
+ ignore_cp_exit_code = parse_status_porcelain(buf.buf, &dirty_submodule, ignore_untracked);
+ if (ignore_cp_exit_code)
break;
- }
}
fclose(fp);
--
2.38.0.rc1.362.ged0d419d3c-goog
next prev parent reply other threads:[~2022-10-11 23:26 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <https://lore.kernel.org/git/20220922232947.631309-1-calvinwan@google.com/>
2022-10-11 23:26 ` [PATCH v2 0/4] submodule: parallelize diff Calvin Wan
2022-10-12 5:52 ` Junio C Hamano
2022-10-14 0:39 ` Calvin Wan
2022-10-11 23:26 ` [PATCH v2 1/4] run-command: add pipe_output_fn to run_processes_parallel_opts Calvin Wan
2022-10-12 7:58 ` Ævar Arnfjörð Bjarmason
2022-10-11 23:26 ` Calvin Wan [this message]
2022-10-12 7:41 ` [PATCH v2 2/4] submodule: move status parsing into function Ævar Arnfjörð Bjarmason
2022-10-12 8:27 ` Ævar Arnfjörð Bjarmason
2022-10-11 23:26 ` [PATCH v2 3/4] diff-lib: refactor match_stat_with_submodule Calvin Wan
2022-10-11 23:26 ` [PATCH v2 4/4] diff-lib: parallelize run_diff_files for submodules Calvin Wan
2022-10-12 8:31 ` Ævar Arnfjörð Bjarmason
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221011232604.839941-3-calvinwan@google.com \
--to=calvinwan@google.com \
--cc=avarab@gmail.com \
--cc=emilyshaffer@google.com \
--cc=git@vger.kernel.org \
--cc=phillip.wood123@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).