git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] submodule--helper: don't print null in 'submodule status'

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Apr 18, 2018, 14:53 UTC
Message-ID
<20180418145337.7591-1-pclouds@gmail.com>

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).

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/submodule--helper.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index a404df3ea4..4dc7d7d29f 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -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
Next: Stefan Beller
Message 1 of 3 in “submodule--helper: don't print null in 'submodule status'”
  1. submodule--helper: don't print null in 'submodule status'Nguyễn Thái Ngọc Duy, Apr 18, 2018
  2. Stefan BellerApr 18, 2018
  3. Junio C HamanoApr 18, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.