summaryrefslogtreecommitdiff
path: root/submodule.c
diff options
context:
space:
mode:
authorStefan Beller <sbeller@google.com>2017-03-25 00:36:06 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-03-27 16:48:19 (GMT)
commitaf6865a7f1e1d915d3b63e998226028ca4abb6ee (patch)
treef94c62954442c50635b09974848596c79f2f890e /submodule.c
parent64f9a946f07d2ca00b34c466654a3f608c78b6af (diff)
downloadgit-af6865a7f1e1d915d3b63e998226028ca4abb6ee.zip
git-af6865a7f1e1d915d3b63e998226028ca4abb6ee.tar.gz
git-af6865a7f1e1d915d3b63e998226028ca4abb6ee.tar.bz2
submodule.c: convert is_submodule_modified to use strbuf_getwholeline
Instead of implementing line reading yet again, make use of our beautiful library function to read one line. By using strbuf_getwholeline instead of strbuf_read, we avoid having to allocate memory for the entire child process output at once. That is, we limit maximum memory usage. Also we can start processing the output as it comes in, no need to wait for all of it. Once we know all information that we care about, we can terminate the child early. In that case we do not care about its exit code as well. By just closing our side of the pipe the child process will get a SIGPIPE signal, which it will not report nor do we report it in finish_command, ac78663b0d (run-command: don't warn on SIGPIPE deaths, 2015-12-29). Helped-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Stefan Beller <sbeller@google.com> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'submodule.c')
-rw-r--r--submodule.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/submodule.c b/submodule.c
index 93e3fef..e72781d 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1041,12 +1041,12 @@ out:
unsigned is_submodule_modified(const char *path, int ignore_untracked)
{
- ssize_t len;
struct child_process cp = CHILD_PROCESS_INIT;
struct strbuf buf = STRBUF_INIT;
+ FILE *fp;
unsigned dirty_submodule = 0;
- const char *line, *next_line;
const char *git_dir;
+ int ignore_cp_exit_code = 0;
strbuf_addf(&buf, "%s/.git", path);
git_dir = read_gitfile(buf.buf);
@@ -1072,29 +1072,27 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
if (start_command(&cp))
die("Could not run 'git status --porcelain' in submodule %s", path);
- len = strbuf_read(&buf, cp.out, 1024);
- line = buf.buf;
- while (len > 2) {
- if ((line[0] == '?') && (line[1] == '?'))
+ fp = xfdopen(cp.out, "r");
+ while (strbuf_getwholeline(&buf, fp, '\n') != EOF) {
+ if ((buf.buf[0] == '?') && (buf.buf[1] == '?'))
dirty_submodule |= DIRTY_SUBMODULE_UNTRACKED;
else
dirty_submodule |= DIRTY_SUBMODULE_MODIFIED;
if ((dirty_submodule & DIRTY_SUBMODULE_MODIFIED) &&
((dirty_submodule & DIRTY_SUBMODULE_UNTRACKED) ||
- ignore_untracked))
- break;
-
- next_line = strchr(line, '\n');
- if (!next_line)
+ 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;
break;
- next_line++;
- len -= (next_line - line);
- line = next_line;
+ }
}
- close(cp.out);
+ fclose(fp);
- if (finish_command(&cp))
+ if (finish_command(&cp) && !ignore_cp_exit_code)
die("'git status --porcelain' failed in submodule %s", path);
strbuf_release(&buf);