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

Re: [PATCH] branch -v: Prevent garbage output on remote refs

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 6, 2008, 10:07 UTC
Message-ID
<7vhcb3fhqx.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<1215336279-99480-1-git-send-email-benji@silverinsanity.com>
Thanks, but I have pushed out a slightly different change.

-- >8 -- branch -r -v: do not spit out garbage

The codepath to emit relationship between the branch and what it tracks forgot to initialize a string buffer stat[] to empty when showing a tracking branch. This moves the emptying so that the buffer starts as empty and stays so when no information is added to fix this issue.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin-branch.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/builtin-branch.c b/builtin-branch.c
index e9423d1..ff71f3d 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -287,10 +287,8 @@ static void fill_tracking_info(char *stat, const char *branch_name)
 	int ours, theirs;
 	struct branch *branch = branch_get(branch_name);
 
-	if (!stat_tracking_info(branch, &ours, &theirs) || (!ours && !theirs)) {
-		stat[0] = '\0';
+	if (!stat_tracking_info(branch, &ours, &theirs) || (!ours && !theirs))
 		return;
-	}
 	if (!ours)
 		sprintf(stat, "[behind %d] ", theirs);
 	else if (!theirs)
@@ -330,6 +328,7 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
 		char stat[128];
 
 		strbuf_init(&subject, 0);
+		stat[0] = '\0';
 
 		commit = lookup_commit(item->sha1);
 		if (commit && !parse_commit(commit)) {
Previous: Brian GernhardtNext: Brian Gernhardt
Message 2 of 3 in “branch -v: Prevent garbage output on remote refs”
  1. branch -v: Prevent garbage output on remote refsBrian Gernhardt, Jul 6, 2008
  2. Junio C HamanoJul 6, 2008
  3. Brian GernhardtJul 6, 2008

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.