Subject: [PATCH 2/8] submodule.c: use argv_array in is_submodule_modified

From: Stefan Beller <[email-masked]>
Date: Thu, 23 Mar 2017 14:09:18 -0700

struct argv_array is easier to use and maintain

Signed-off-by: Stefan Beller <[email-masked]>
---
 submodule.c | 43 +++++++++++++++++++++----------------------
 1 file changed, 21 insertions(+), 22 deletions(-)

diff --git a/submodule.c b/submodule.c
index d355ddb46b..dc61ca7103 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1041,9 +1041,11 @@ int fetch_populated_submodules(const struct argv_array *options,
 
 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;
 	unsigned dirty_submodule = 0;
+	const char *line, *next_line;
 	const char *git_dir;
 
 	strbuf_addf(&buf, "%s/.git", path);
@@ -1068,35 +1070,32 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
 	cp.out = -1;
 	cp.dir = path;
 	if (start_command(&cp))
-		die("Could not run 'git status --porcelain=2' in submodule %s", path);
+		die("Could not run 'git status --porcelain' in submodule %s", path);
 
-	while (strbuf_getwholeline_fd(&buf, cp.out, '\n') != EOF) {
-		/* regular untracked files */
-		if (buf.buf[0] == '?')
+	len = strbuf_read(&buf, cp.out, 1024);
+	line = buf.buf;
+	while (len > 2) {
+		if ((line[0] == '?') && (line[1] == '?')) {
 			dirty_submodule |= DIRTY_SUBMODULE_UNTRACKED;
-
-		/* regular unmerged and renamed files */
-		if (buf.buf[0] == 'u' ||
-		    buf.buf[0] == '1' ||
-		    buf.buf[0] == '2') {
-			if (buf.buf[5] == 'S') {
-				/* nested submodule handling */
-				if (buf.buf[6] == 'C' || buf.buf[7] == 'M')
-					dirty_submodule |= DIRTY_SUBMODULE_MODIFIED;
-				if (buf.buf[8] == 'U')
-					dirty_submodule |= DIRTY_SUBMODULE_UNTRACKED;
-			} else
-				dirty_submodule |= DIRTY_SUBMODULE_MODIFIED;
-		}
-
-		if (dirty_submodule & DIRTY_SUBMODULE_MODIFIED &&
-		    dirty_submodule & DIRTY_SUBMODULE_UNTRACKED)
+			if (dirty_submodule & DIRTY_SUBMODULE_MODIFIED)
+				break;
+		} else {
+			dirty_submodule |= DIRTY_SUBMODULE_MODIFIED;
+			if (ignore_untracked ||
+			    (dirty_submodule & DIRTY_SUBMODULE_UNTRACKED))
 				break;
+		}
+		next_line = strchr(line, '\n');
+		if (!next_line)
+			break;
+		next_line++;
+		len -= (next_line - line);
+		line = next_line;
 	}
 	close(cp.out);
 
 	if (finish_command(&cp))
-		die("'git status --porcelain=2' failed in submodule %s", path);
+		die("'git status --porcelain' failed in submodule %s", path);
 
 	strbuf_release(&buf);
 	return dirty_submodule;
-- 
2.12.1.438.gb674c4c09c