git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Stefan Beller <sbeller@google.com>
To: gitster@pobox.com
Cc: git@vger.kernel.org, jrnieder@gmail.com,
	Stefan Beller <sbeller@google.com>
Subject: [PATCH 1/3] submodule.c: port is_submodule_modified to use porcelain 2
Date: Wed, 22 Mar 2017 17:43:27 -0700	[thread overview]
Message-ID: <20170323004329.15892-2-sbeller@google.com> (raw)
In-Reply-To: <20170323004329.15892-1-sbeller@google.com>

Migrate 'is_submodule_modified' to the new porcelain format of
git-status.

As the old porcelain only reported ' M' for submodules, no
matter what happened inside the submodule (untracked files,
changes to tracked files or move of HEAD), the new API
properly reports the different scenarios.

In a followup patch we will make use of these finer grained
reporting for git-status.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 submodule.c | 53 ++++++++++++++++++++++++-----------------------------
 1 file changed, 24 insertions(+), 29 deletions(-)

diff --git a/submodule.c b/submodule.c
index 3200b7bb2b..d355ddb46b 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1041,17 +1041,9 @@ 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;
-	const char *argv[] = {
-		"status",
-		"--porcelain",
-		NULL,
-		NULL,
-	};
 	struct strbuf buf = STRBUF_INIT;
 	unsigned dirty_submodule = 0;
-	const char *line, *next_line;
 	const char *git_dir;
 
 	strbuf_addf(&buf, "%s/.git", path);
@@ -1066,42 +1058,45 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
 	}
 	strbuf_reset(&buf);
 
+	argv_array_pushl(&cp.args, "status", "--porcelain=2", NULL);
 	if (ignore_untracked)
-		argv[2] = "-uno";
+		argv_array_push(&cp.args, "-uno");
 
-	cp.argv = argv;
 	prepare_submodule_repo_env(&cp.env_array);
 	cp.git_cmd = 1;
 	cp.no_stdin = 1;
 	cp.out = -1;
 	cp.dir = path;
 	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);
 
-	len = strbuf_read(&buf, cp.out, 1024);
-	line = buf.buf;
-	while (len > 2) {
-		if ((line[0] == '?') && (line[1] == '?')) {
+	while (strbuf_getwholeline_fd(&buf, cp.out, '\n') != EOF) {
+		/* regular untracked files */
+		if (buf.buf[0] == '?')
 			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;
+
+		/* 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;
 		}
-		next_line = strchr(line, '\n');
-		if (!next_line)
-			break;
-		next_line++;
-		len -= (next_line - line);
-		line = next_line;
+
+		if (dirty_submodule & DIRTY_SUBMODULE_MODIFIED &&
+		    dirty_submodule & DIRTY_SUBMODULE_UNTRACKED)
+				break;
 	}
 	close(cp.out);
 
 	if (finish_command(&cp))
-		die("'git status --porcelain' failed in submodule %s", path);
+		die("'git status --porcelain=2' failed in submodule %s", path);
 
 	strbuf_release(&buf);
 	return dirty_submodule;
-- 
2.12.1.432.gfe308fe33c.dirty


  reply	other threads:[~2017-03-23  0:43 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-23  0:43 [PATCHv3 0/3] short status: improve reporting for submodule changes Stefan Beller
2017-03-23  0:43 ` Stefan Beller [this message]
2017-03-23  0:53   ` [PATCH 1/3] submodule.c: port is_submodule_modified to use porcelain 2 Jonathan Nieder
2017-03-23  6:09     ` Junio C Hamano
2017-03-23 18:47       ` Stefan Beller
2017-03-23  0:43 ` [PATCH 2/3] submodule.c, is_submodule_modified: stricter checking for submodules Stefan Beller
2017-03-23  0:54   ` Jonathan Nieder
2017-03-23  0:43 ` [PATCH 3/3] short status: improve reporting for submodule changes Stefan Beller
2017-03-23  1:06   ` Jonathan Nieder
2017-03-23 21:09 ` [PATCH 0/8] " Stefan Beller
2017-03-23 21:09   ` [PATCH 1/8] submodule.c: port is_submodule_modified to use porcelain 2 Stefan Beller
2017-03-23 21:09   ` [PATCH 2/8] submodule.c: use argv_array in is_submodule_modified Stefan Beller
2017-03-23 21:09   ` [PATCH 3/8] submodule.c: convert is_submodule_modified to use strbuf_getwholeline_fd Stefan Beller
2017-03-23 21:09   ` [PATCH 4/8] submodule.c: port is_submodule_modified to use porcelain 2 Stefan Beller
2017-03-23 21:09   ` [PATCH 5/8] submodule.c: factor out early loop termination in is_submodule_modified Stefan Beller
2017-03-23 21:09   ` [PATCH 6/8] submodule.c: stricter checking for submodules " Stefan Beller
2017-03-23 21:09   ` [PATCH 7/8] short status: improve reporting for submodule changes Stefan Beller
2017-03-23 21:09   ` [PATCH 8/8] submodule.c: correctly handle nested submodules in is_submodule_modified Stefan Beller
2017-03-23 21:11   ` [PATCH 0/8] short status: improve reporting for submodule changes Stefan Beller
2017-03-23 22:33     ` [PATCH v5 0/7] " Stefan Beller
2017-03-23 22:33       ` [PATCH 1/7] submodule.c: use argv_array in is_submodule_modified Stefan Beller
2017-03-23 22:36         ` Jonathan Nieder
2017-03-23 22:33       ` [PATCH 2/7] submodule.c: convert is_submodule_modified to use strbuf_getwholeline_fd Stefan Beller
2017-03-23 22:50         ` Jonathan Nieder
2017-03-23 23:04           ` Stefan Beller
2017-03-23 23:11             ` Stefan Beller
2017-03-23 22:33       ` [PATCH 3/7] submodule.c: port is_submodule_modified to use porcelain 2 Stefan Beller
2017-03-23 22:33       ` [PATCH 4/7] submodule.c: factor out early loop termination in is_submodule_modified Stefan Beller
2017-03-23 22:33       ` [PATCH 5/7] submodule.c: stricter checking for submodules " Stefan Beller
2017-03-23 22:33       ` [PATCH 6/7] short status: improve reporting for submodule changes Stefan Beller
2017-03-24 18:28         ` [PATCH v6 0/7] " Stefan Beller
2017-03-24 18:28           ` [PATCH 1/7] submodule.c: use argv_array in is_submodule_modified Stefan Beller
2017-03-24 22:25             ` Jonathan Nieder
2017-03-24 18:28           ` [PATCH 2/7] submodule.c: factor out early loop termination " Stefan Beller
2017-03-24 22:30             ` Jonathan Nieder
2017-03-24 18:28           ` [PATCH 3/7] submodule.c: convert is_submodule_modified to use strbuf_getwholeline Stefan Beller
2017-03-24 22:38             ` Jonathan Nieder
2017-03-25  0:12               ` Stefan Beller
2017-03-24 18:28           ` [PATCH 4/7] submodule.c: port is_submodule_modified to use porcelain 2 Stefan Beller
2017-03-24 22:41             ` Jonathan Nieder
2017-03-24 18:29           ` [PATCH 5/7] submodule.c: stricter checking for submodules in is_submodule_modified Stefan Beller
2017-03-24 22:42             ` Jonathan Nieder
2017-03-24 18:29           ` [PATCH 6/7] short status: improve reporting for submodule changes Stefan Beller
2017-03-24 23:06             ` Jonathan Nieder
2017-03-24 18:29           ` [PATCH 7/7] submodule.c: correctly handle nested submodules in is_submodule_modified Stefan Beller
2017-03-24 23:31             ` Jonathan Nieder
2017-03-25  0:25               ` Stefan Beller
2017-03-25  0:36           ` [PATCH v7 0/7] short status: improve reporting for submodule changes Stefan Beller
2017-03-25  0:36             ` [PATCH 1/7] submodule.c: use argv_array in is_submodule_modified Stefan Beller
2017-03-25  0:36             ` [PATCH 2/7] submodule.c: factor out early loop termination " Stefan Beller
2017-03-25  0:36             ` [PATCH 3/7] submodule.c: convert is_submodule_modified to use strbuf_getwholeline Stefan Beller
2017-03-25  0:36             ` [PATCH 4/7] submodule.c: port is_submodule_modified to use porcelain 2 Stefan Beller
2017-03-25  0:36             ` [PATCH 5/7] submodule.c: stricter checking for submodules in is_submodule_modified Stefan Beller
2017-03-25  0:36             ` [PATCH 6/7] short status: improve reporting for submodule changes Stefan Beller
2017-03-25  0:36             ` [PATCH 7/7] submodule.c: correctly handle nested submodules in is_submodule_modified Stefan Beller
2017-03-27 21:46               ` Junio C Hamano
2017-03-28  1:05                 ` Jonathan Nieder
2017-03-30 18:18                   ` Junio C Hamano
2017-03-28 21:20                 ` Stefan Beller
2017-03-25  1:35             ` [PATCH v7 0/7] short status: improve reporting for submodule changes Jonathan Nieder
2017-03-28 23:09             ` [PATCH v8 " Stefan Beller
2017-03-28 23:09               ` [PATCH 1/2] " Stefan Beller
2017-03-28 23:24                 ` Jonathan Nieder
2017-03-28 23:09               ` [PATCH 2/2] submodule.c: correctly handle nested submodules in is_submodule_modified Stefan Beller
2017-03-28 23:42                 ` Jonathan Nieder
2017-03-29 22:00                   ` Stefan Beller
2017-03-29 22:26               ` [PATCHv9 (6,7)/7] short status: improve reporting for submodule changes Stefan Beller
2017-03-29 22:26                 ` [PATCH 1/2] " Stefan Beller
2017-03-29 23:09                   ` Jonathan Nieder
2017-03-29 22:26                 ` [PATCH 2/2] submodule.c: correctly handle nested submodules in is_submodule_modified Stefan Beller
2017-03-29 23:13                   ` Jonathan Nieder
2017-03-30 18:28                     ` Junio C Hamano
2017-03-23 22:33       ` [PATCH 7/7] " Stefan Beller
  -- strict thread matches above, loose matches on Subject: below --
2017-03-21  0:11 [PATCH 0/3] git-describe deals gracefully with broken submodules Stefan Beller
2017-03-21  0:11 ` [PATCH 1/3] submodule.c: port is_submodule_modified to use porcelain 2 Stefan Beller

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170323004329.15892-2-sbeller@google.com \
    --to=sbeller@google.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).