Skip to content

Commit 0b5e2ea

Browse files
pcloudsgitster
authored andcommitted
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). Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Reviewed-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a9f8a37 commit 0b5e2ea

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

builtin/submodule--helper.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,12 @@ static void print_status(unsigned int flags, char state, const char *path,
562562

563563
printf("%c%s %s", state, oid_to_hex(oid), displaypath);
564564

565-
if (state == ' ' || state == '+')
566-
printf(" (%s)", compute_rev_name(path, oid_to_hex(oid)));
565+
if (state == ' ' || state == '+') {
566+
const char *name = compute_rev_name(path, oid_to_hex(oid));
567+
568+
if (name)
569+
printf(" (%s)", name);
570+
}
567571

568572
printf("\n");
569573
}

0 commit comments

Comments
 (0)