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 <sbeller@google.com>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Stefan Beller 2017-03-24 17:36:07 -07:00 коммит произвёл Junio C Hamano
Родитель af6865a7f1
Коммит fcecf0b968
1 изменённых файлов: 5 добавлений и 4 удалений

Просмотреть файл

@ -1060,7 +1060,7 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
} }
strbuf_reset(&buf); strbuf_reset(&buf);
argv_array_pushl(&cp.args, "status", "--porcelain", NULL); argv_array_pushl(&cp.args, "status", "--porcelain=2", NULL);
if (ignore_untracked) if (ignore_untracked)
argv_array_push(&cp.args, "-uno"); argv_array_push(&cp.args, "-uno");
@ -1070,11 +1070,12 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
cp.out = -1; cp.out = -1;
cp.dir = path; cp.dir = path;
if (start_command(&cp)) if (start_command(&cp))
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"); fp = xfdopen(cp.out, "r");
while (strbuf_getwholeline(&buf, fp, '\n') != EOF) { while (strbuf_getwholeline(&buf, fp, '\n') != EOF) {
if ((buf.buf[0] == '?') && (buf.buf[1] == '?')) /* regular untracked files */
if (buf.buf[0] == '?')
dirty_submodule |= DIRTY_SUBMODULE_UNTRACKED; dirty_submodule |= DIRTY_SUBMODULE_UNTRACKED;
else else
dirty_submodule |= DIRTY_SUBMODULE_MODIFIED; dirty_submodule |= DIRTY_SUBMODULE_MODIFIED;
@ -1093,7 +1094,7 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
fclose(fp); fclose(fp);
if (finish_command(&cp) && !ignore_cp_exit_code) if (finish_command(&cp) && !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(&buf); strbuf_release(&buf);
return dirty_submodule; return dirty_submodule;