diff mbox series

[v7,2/7] submodule: strbuf variable rename

Message ID 20230207181706.363453-3-calvinwan@google.com (mailing list archive)
State New, archived
Headers show
Series submodule: parallelize diff | expand

Commit Message

Calvin Wan Feb. 7, 2023, 6:17 p.m. UTC
A prepatory change for a future patch that moves the status parsing
logic to a separate function.

Signed-off-by: Calvin Wan <calvinwan@google.com>
---
 submodule.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

Comments

Ævar Arnfjörð Bjarmason Feb. 7, 2023, 10:47 p.m. UTC | #1
On Tue, Feb 07 2023, Calvin Wan wrote:

> A prepatory change for a future patch that moves the status parsing
> logic to a separate function.

Ah, I think I suggested splitting this up in some previous round, and
coming back to this this + the next patch look very nice with the move
detection, thanks!
>  	fp = xfdopen(cp.out, "r");
>  	while (strbuf_getwholeline(&buf, fp, '\n') != EOF) {
> +		char *str = buf.buf;
> +		const size_t len = buf.len;
> +
>  		/* regular untracked files */
> -		if (buf.buf[0] == '?')
> +		if (str[0] == '?')
>  			dirty_submodule |= DIRTY_SUBMODULE_UNTRACKED;

I'll only add that we could also do this on top:
	
	diff --git a/submodule.c b/submodule.c
	index c7c6bfb2e26..eeb940d96a0 100644
	--- a/submodule.c
	+++ b/submodule.c
	@@ -1875,7 +1875,7 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
	 	struct child_process cp = CHILD_PROCESS_INIT;
	 	struct strbuf buf = STRBUF_INIT;
	 	FILE *fp;
	-	unsigned dirty_submodule = 0;
	+	unsigned dirty_submodule0 = 0;
	 	const char *git_dir;
	 	int ignore_cp_exit_code = 0;
	 
	@@ -1908,10 +1908,11 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
	 	while (strbuf_getwholeline(&buf, fp, '\n') != EOF) {
	 		char *str = buf.buf;
	 		const size_t len = buf.len;
	+		unsigned *dirty_submodule = &dirty_submodule0;
	 
	 		/* regular untracked files */
	 		if (str[0] == '?')
	-			dirty_submodule |= DIRTY_SUBMODULE_UNTRACKED;
	+			*dirty_submodule |= DIRTY_SUBMODULE_UNTRACKED;
	 
	 		if (str[0] == 'u' ||
	 		    str[0] == '1' ||
	@@ -1923,17 +1924,17 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
	 
	 			if (str[5] == 'S' && str[8] == 'U')
	 				/* nested untracked file */
	-				dirty_submodule |= DIRTY_SUBMODULE_UNTRACKED;
	+				*dirty_submodule |= DIRTY_SUBMODULE_UNTRACKED;
	 
	 			if (str[0] == 'u' ||
	 			    str[0] == '2' ||
	 			    memcmp(str + 5, "S..U", 4))
	 				/* other change */
	-				dirty_submodule |= DIRTY_SUBMODULE_MODIFIED;
	+				*dirty_submodule |= DIRTY_SUBMODULE_MODIFIED;
	 		}
	 
	-		if ((dirty_submodule & DIRTY_SUBMODULE_MODIFIED) &&
	-		    ((dirty_submodule & DIRTY_SUBMODULE_UNTRACKED) ||
	+		if ((*dirty_submodule & DIRTY_SUBMODULE_MODIFIED) &&
	+		    ((*dirty_submodule & DIRTY_SUBMODULE_UNTRACKED) ||
	 		     ignore_untracked)) {
	 			/*
	 			 * We're not interested in any further information from
	@@ -1949,7 +1950,7 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
	 		die(_("'git status --porcelain=2' failed in submodule %s"), path);
	 
	 	strbuf_release(&buf);
	-	return dirty_submodule;
	+	return dirty_submodule0;
	 }
	 
	 int submodule_uses_gitfile(const char *path)

Which, if we're massaging this for a subsequent smaller diff we can do
to make only the comment adjustment part of this be a non-moved line.
Calvin Wan Feb. 8, 2023, 10:59 p.m. UTC | #2
> I'll only add that we could also do this on top:
>
>         diff --git a/submodule.c b/submodule.c
>         index c7c6bfb2e26..eeb940d96a0 100644
>         --- a/submodule.c
>         +++ b/submodule.c
>         @@ -1875,7 +1875,7 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
>                 struct child_process cp = CHILD_PROCESS_INIT;
>                 struct strbuf buf = STRBUF_INIT;
>                 FILE *fp;
>         -       unsigned dirty_submodule = 0;
>         +       unsigned dirty_submodule0 = 0;
>                 const char *git_dir;
>                 int ignore_cp_exit_code = 0;
>
>         @@ -1908,10 +1908,11 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
>                 while (strbuf_getwholeline(&buf, fp, '\n') != EOF) {
>                         char *str = buf.buf;
>                         const size_t len = buf.len;
>         +               unsigned *dirty_submodule = &dirty_submodule0;
>
>                         /* regular untracked files */
>                         if (str[0] == '?')
>         -                       dirty_submodule |= DIRTY_SUBMODULE_UNTRACKED;
>         +                       *dirty_submodule |= DIRTY_SUBMODULE_UNTRACKED;
>
>                         if (str[0] == 'u' ||
>                             str[0] == '1' ||
>         @@ -1923,17 +1924,17 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
>
>                                 if (str[5] == 'S' && str[8] == 'U')
>                                         /* nested untracked file */
>         -                               dirty_submodule |= DIRTY_SUBMODULE_UNTRACKED;
>         +                               *dirty_submodule |= DIRTY_SUBMODULE_UNTRACKED;
>
>                                 if (str[0] == 'u' ||
>                                     str[0] == '2' ||
>                                     memcmp(str + 5, "S..U", 4))
>                                         /* other change */
>         -                               dirty_submodule |= DIRTY_SUBMODULE_MODIFIED;
>         +                               *dirty_submodule |= DIRTY_SUBMODULE_MODIFIED;
>                         }
>
>         -               if ((dirty_submodule & DIRTY_SUBMODULE_MODIFIED) &&
>         -                   ((dirty_submodule & DIRTY_SUBMODULE_UNTRACKED) ||
>         +               if ((*dirty_submodule & DIRTY_SUBMODULE_MODIFIED) &&
>         +                   ((*dirty_submodule & DIRTY_SUBMODULE_UNTRACKED) ||
>                              ignore_untracked)) {
>                                 /*
>                                  * We're not interested in any further information from
>         @@ -1949,7 +1950,7 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
>                         die(_("'git status --porcelain=2' failed in submodule %s"), path);
>
>                 strbuf_release(&buf);
>         -       return dirty_submodule;
>         +       return dirty_submodule0;
>          }
>
>          int submodule_uses_gitfile(const char *path)
>
> Which, if we're massaging this for a subsequent smaller diff we can do
> to make only the comment adjustment part of this be a non-moved line.

Ah that's a neat little trick -- I'll save this one for the next time I do a
refactor like this :)
diff mbox series

Patch

diff --git a/submodule.c b/submodule.c
index fae24ef34a..faf37c1101 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1906,25 +1906,28 @@  unsigned is_submodule_modified(const char *path, int ignore_untracked)
 
 	fp = xfdopen(cp.out, "r");
 	while (strbuf_getwholeline(&buf, fp, '\n') != EOF) {
+		char *str = buf.buf;
+		const size_t len = buf.len;
+
 		/* regular untracked files */
-		if (buf.buf[0] == '?')
+		if (str[0] == '?')
 			dirty_submodule |= DIRTY_SUBMODULE_UNTRACKED;
 
-		if (buf.buf[0] == 'u' ||
-		    buf.buf[0] == '1' ||
-		    buf.buf[0] == '2') {
+		if (str[0] == 'u' ||
+		    str[0] == '1' ||
+		    str[0] == '2') {
 			/* T = line type, XY = status, SSSS = submodule state */
-			if (buf.len < strlen("T XY SSSS"))
+			if (len < strlen("T XY SSSS"))
 				BUG("invalid status --porcelain=2 line %s",
-				    buf.buf);
+				    str);
 
-			if (buf.buf[5] == 'S' && buf.buf[8] == 'U')
+			if (str[5] == 'S' && str[8] == 'U')
 				/* nested untracked file */
 				dirty_submodule |= DIRTY_SUBMODULE_UNTRACKED;
 
-			if (buf.buf[0] == 'u' ||
-			    buf.buf[0] == '2' ||
-			    memcmp(buf.buf + 5, "S..U", 4))
+			if (str[0] == 'u' ||
+			    str[0] == '2' ||
+			    memcmp(str + 5, "S..U", 4))
 				/* other change */
 				dirty_submodule |= DIRTY_SUBMODULE_MODIFIED;
 		}