[PATCH 4/7] submodule.c: port is_submodule_modified to use porcelain 2
Migrate 'is_submodule_modified' to the new porcelain format of git-status. This conversion attempts to convert faithfully, i.e. the behavior ought to be exactly the same. As the output in the parsing only distinguishes between untracked files and the rest, this is easy to port to the new format, as we only need to identify untracked files and the rest is handled in the "else" case. untracked files are indicated by only a single question mark instead of two question marks, so the conversion is easy. Signed-off-by: Stefan BellerReviewed-by: Jonathan Nieder --- submodule.c | 9 + 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/submodule.c b/submodule.c index e72781d9f2..5865795b9f 100644 --- a/submodule.c +++ b/submodule.c @@ -1060,7 +1060,7 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked) } strbuf_reset(); - argv_array_pushl(, "status", "--porcelain", NULL); + argv_array_pushl(, "status", "--porcelain=2", NULL); if (ignore_untracked) argv_array_push(, "-uno"); @@ -1070,11 +1070,12 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked) cp.out = -1; cp.dir = path; if (start_command()) - die("Could not run 'git status --porcelain' in submodule %s", path); + die("Could not run 'git status --porcelain=2' in submodule %s", path); fp = xfdopen(cp.out, "r"); while (strbuf_getwholeline(, fp, '\n') != EOF) { - if ((buf.buf[0] == '?') && (buf.buf[1] == '?')) + /* regular untracked files */ + if (buf.buf[0] == '?') dirty_submodule |= DIRTY_SUBMODULE_UNTRACKED; else dirty_submodule |= DIRTY_SUBMODULE_MODIFIED; @@ -1093,7 +1094,7 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked) fclose(fp); if (finish_command() && !ignore_cp_exit_code) - die("'git status --porcelain' failed in submodule %s", path); + die("'git status --porcelain=2' failed in submodule %s", path); strbuf_release(); return dirty_submodule; -- 2.12.0.rc1.49.gdeb397943c.dirty
Re: [PATCH 4/7] submodule.c: port is_submodule_modified to use porcelain 2
Stefan Beller wrote: [...] > --- a/submodule.c > +++ b/submodule.c [...] > @@ -1070,11 +1070,12 @@ unsigned is_submodule_modified(const char *path, int > ignore_untracked) [...] > while (strbuf_getwholeline(, fp, '\n') != EOF) { > - if ((buf.buf[0] == '?') && (buf.buf[1] == '?')) > + /* regular untracked files */ > + if (buf.buf[0] == '?') > dirty_submodule |= DIRTY_SUBMODULE_UNTRACKED; > else > dirty_submodule |= DIRTY_SUBMODULE_MODIFIED; At first I didn't believe it could be so simple. :) Unlike ordinary files that use 1, 2, or u, ignored files use '!'. You're not passing --ignored so you don't have to worry about them. Reviewed-by: Jonathan NiederVery nice.
[PATCH 4/7] submodule.c: port is_submodule_modified to use porcelain 2
Migrate 'is_submodule_modified' to the new porcelain format of git-status. This conversion attempts to convert faithfully, i.e. the behavior ought to be exactly the same. As the output in the parsing only distinguishes between untracked files and the rest, this is easy to port to the new format, as we only need to identify untracked files and the rest is handled in the "else" case. untracked files are indicated by only a single question mark instead of two question marks, so the conversion is easy. Signed-off-by: Stefan Beller--- submodule.c | 9 + 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/submodule.c b/submodule.c index 0c43f9f2b1..256f15fde1 100644 --- a/submodule.c +++ b/submodule.c @@ -1060,7 +1060,7 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked) } strbuf_reset(); - argv_array_pushl(, "status", "--porcelain", NULL); + argv_array_pushl(, "status", "--porcelain=2", NULL); if (ignore_untracked) argv_array_push(, "-uno"); @@ -1070,11 +1070,12 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked) cp.out = -1; cp.dir = path; if (start_command()) - die("Could not run 'git status --porcelain' in submodule %s", path); + die("Could not run 'git status --porcelain=2' in submodule %s", path); fp = xfdopen(cp.out, "r"); while (strbuf_getwholeline(, fp, '\n') != EOF) { - if ((buf.buf[0] == '?') && (buf.buf[1] == '?')) + /* regular untracked files */ + if (buf.buf[0] == '?') dirty_submodule |= DIRTY_SUBMODULE_UNTRACKED; else dirty_submodule |= DIRTY_SUBMODULE_MODIFIED; @@ -1093,7 +1094,7 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked) fclose(fp); if (finish_command() && !ignore_cp_exit_code) - die("'git status --porcelain' failed in submodule %s", path); + die("'git status --porcelain=2' failed in submodule %s", path); strbuf_release(); return dirty_submodule; -- 2.12.1.437.g2b7623d507