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

[PATCH 2/5] wt-status: exit early using goto in wt_shortstatus_print_tracking()

From
René Scharfe <l.s.r@web.de>
Date
Oct 31, 2015, 17:36 UTC
Message-ID
<5634FC01.8050601@web.de>
In-Reply-To
<5634FB59.1000506@web.de>

Deduplicate printing the line terminator by jumping to the end of the function.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 wt-status.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/wt-status.c b/wt-status.c
index 3e3b8c0..083328f 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1658,10 +1658,8 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
 	color_fprintf(s->fp, branch_color_local, "%s", branch_name);
 
 	if (stat_tracking_info(branch, &num_ours, &num_theirs, &base) < 0) {
-		if (!base) {
-			fputc(s->null_termination ? '\0' : '\n', s->fp);
-			return;
-		}
+		if (!base)
+			goto conclude;
 
 		upstream_is_gone = 1;
 	}
@@ -1671,10 +1669,8 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
 	color_fprintf(s->fp, branch_color_remote, "%s", base);
 	free((char *)base);
 
-	if (!upstream_is_gone && !num_ours && !num_theirs) {
-		fputc(s->null_termination ? '\0' : '\n', s->fp);
-		return;
-	}
+	if (!upstream_is_gone && !num_ours && !num_theirs)
+		goto conclude;
 
 #define LABEL(string) (s->no_gettext ? (string) : _(string))
 
@@ -1695,6 +1691,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
 	}
 
 	color_fprintf(s->fp, header_color, "]");
+ conclude:
 	fputc(s->null_termination ? '\0' : '\n', s->fp);
 }
 
-- 
2.6.2
Previous: René ScharfeNext: René Scharfe
Message 3 of 10 in “wt-status: fix an invalid memory read, clean up”
  1. 0/5 wt-status: fix an invalid memory read, clean upRené Scharfe, Oct 31, 2015
  2. 1/5 t7060: add test for status --branch on a detached HEADRené Scharfe, Oct 31, 2015
  3. 2/5 wt-status: exit early using goto in wt_shortstatus_print_tracking()René Scharfe, Oct 31, 2015
  4. 3/5 wt-status: avoid building bogus branch name with detached HEADRené Scharfe, Oct 31, 2015
  5. Junio C HamanoNov 1, 2015
  6. René ScharfeNov 1, 2015
  7. 4/5 wt-status: don't skip a magical number of characters blindlyRené Scharfe, Oct 31, 2015
  8. Junio C HamanoNov 1, 2015
  9. Junio C HamanoNov 1, 2015
  10. 5/5 wt-status: use skip_prefix() to get rid of magic string length constantsRené Scharfe, Oct 31, 2015

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.