Skip to contentSkip to conversation

submodule--helper: don't print null in 'submodule status'

PATCH In review Nguyễn Thái Ngọc Duy 3 participants 3 messages Apr 18, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 submodule--helper: don't print null in 'submodule status'

The function compute_rev_name() can return NULL sometimes (e.g. right after 'submodule init'). The current code makes 'submodule status' print this:

19d97bf5af05312267c2e874ee6bcf584d9e9681 sha1collisiondetection ((null))

This ugly 'null' adds no value to the user using this command. More importantly printf() on some platform can't handle NULL as a string and will crash instead of printing '(null)'.

Check for this and skip printing this part (the alternative is printing '(n/a)' or something but I think that is just noise).

---
 builtin/submodule--helper.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
builtin/submodule--helper.c +6 -2
index a404df3ea4..4dc7d7d29f 100644
@@ -596,8 +596,12 @@ static void print_status(unsigned int flags, char state, const char *path,
 
 	printf("%c%s %s", state, oid_to_hex(oid), displaypath);
 
-	if (state == ' ' || state == '+')
-		printf(" (%s)", compute_rev_name(path, oid_to_hex(oid)));
+	if (state == ' ' || state == '+') {
+		const char *name = compute_rev_name(path, oid_to_hex(oid));
+
+		if (name)
+			printf(" (%s)", name);
+	}
 
 	printf("\n");
 }
Signature · 1 line
2.17.0.367.g5dd2e386c3
Reviewed-by on v1 1/1
#1 lore raw

Hi Nguyễn,

Quoted 4 lines · Nguyễn Thái Ngọc Duy

The function compute_rev_name() can return NULL sometimes (e.g. right after 'submodule init'). The current code makes 'submodule status' print this:

Quoted 8 lines

19d97bf5af05312267c2e874ee6bcf584d9e9681 sha1collisiondetection ((null))

This ugly 'null' adds no value to the user using this command. More importantly printf() on some platform can't handle NULL as a string and will crash instead of printing '(null)'.

Check for this and skip printing this part (the alternative is printing '(n/a)' or something but I think that is just noise).

This patch restores the behavior from before a9f8a37584 (submodule:
port submodule subcommand 'status' from shell to C, 2017-10-06), so this is the right way to go instead of the alternatives you considered.

Thanks!

Quoted 27 lines
---
 builtin/submodule--helper.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
builtin/submodule--helper.c +6 -3
index a404df3ea4..4dc7d7d29f 100644
@@ -596,8 +596,12 @@ static void print_status(unsigned int flags, char state, const char *path,
 
        printf("%c%s %s", state, oid_to_hex(oid), displaypath);
 
-       if (state == ' ' || state == '+')
-               printf(" (%s)", compute_rev_name(path, oid_to_hex(oid)));
+       if (state == ' ' || state == '+') {
+               const char *name = compute_rev_name(path, oid_to_hex(oid));
+
+               if (name)
+                       printf(" (%s)", name);
+       }
 
        printf("\n");
 }
--

2.17.0.367.g5dd2e386c3

#2 lore raw
Quoted 16 lines · Stefan Beller

Hi Nguyễn,

Quoted 4 lines · Nguyễn Thái Ngọc Duy

The function compute_rev_name() can return NULL sometimes (e.g. right after 'submodule init'). The current code makes 'submodule status' print this:

Quoted 8 lines

19d97bf5af05312267c2e874ee6bcf584d9e9681 sha1collisiondetection ((null))

This ugly 'null' adds no value to the user using this command. More importantly printf() on some platform can't handle NULL as a string and will crash instead of printing '(null)'.

Check for this and skip printing this part (the alternative is printing '(n/a)' or something but I think that is just noise).

Quoted 7 lines

This patch restores the behavior from before a9f8a37584 (submodule:
port submodule subcommand 'status' from shell to C, 2017-10-06), so this is the right way to go instead of the alternatives you considered.

Thanks!

Excellent. Thanks, both.

Will queue.

Quoted 28 lines
Quoted 28 lines
---
 builtin/submodule--helper.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
builtin/submodule--helper.c +6 -3
index a404df3ea4..4dc7d7d29f 100644
@@ -596,8 +596,12 @@ static void print_status(unsigned int flags, char state, const char *path,
 
        printf("%c%s %s", state, oid_to_hex(oid), displaypath);
 
-       if (state == ' ' || state == '+')
-               printf(" (%s)", compute_rev_name(path, oid_to_hex(oid)));
+       if (state == ' ' || state == '+') {
+               const char *name = compute_rev_name(path, oid_to_hex(oid));
+
+               if (name)
+                       printf(" (%s)", name);
+       }
 
        printf("\n");
 }
--

2.17.0.367.g5dd2e386c3