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

[PATCH 4/5] status: fix null termination with "-b"

From
Jeff King <peff@peff.net>
Date
May 7, 2012, 21:24 UTC
Message-ID
<20120507212438.GD19567@sigill.intra.peff.net>
In-Reply-To
<20120507212125.GA19532@sigill.intra.peff.net>

When the "-z" option is given to status, we are supposed to NUL-terminate each record. However, the "-b" code to show the tracking branch did not respect this, and always ended with a newline.

Signed-off-by: Jeff King <peff@peff.net>
---
 t/t7508-status.sh | 9 +++++++++
 wt-status.c       | 7 ++++---
 2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index 8f5cfac..f60f49b 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -295,6 +295,15 @@ test_expect_success 'status -s -b' '
 
 '
 
+test_expect_success 'status -s -z -b' '
+	tr "\\n" Q <expect >expect.q &&
+	mv expect.q expect &&
+	git status -s -z -b >output &&
+	nul_to_q <output >output.q &&
+	mv output.q output &&
+	test_cmp expect output
+'
+
 test_expect_success 'setup dir3' '
 	mkdir dir3 &&
 	: >dir3/untracked1 &&
diff --git a/wt-status.c b/wt-status.c
index 284dc61..21c0d4d 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -913,8 +913,8 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
 	if (s->is_initial)
 		color_fprintf(s->fp, header_color, _("Initial commit on "));
 	if (!stat_tracking_info(branch, &num_ours, &num_theirs)) {
-		color_fprintf_ln(s->fp, branch_color_local,
-			"%s", branch_name);
+		color_fprintf(s->fp, branch_color_local, "%s", branch_name);
+		fputc(s->null_termination ? '\0' : '\n', s->fp);
 		return;
 	}
 
@@ -938,7 +938,8 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
 		color_fprintf(s->fp, branch_color_remote, "%d", num_theirs);
 	}
 
-	color_fprintf_ln(s->fp, header_color, "]");
+	color_fprintf(s->fp, header_color, "]");
+	fputc(s->null_termination ? '\0' : '\n', s->fp);
 }
 
 void wt_shortstatus_print(struct wt_status *s, int show_branch)
-- 
1.7.10.1.12.gd79f7ab
Previous: Jeff KingNext: Jeff King
Message 10 of 16 in “correct git-status Porcelain Format documentation”
  1. correct git-status Porcelain Format documentationJeff King, May 6, 2012
  2. Jeff KingMay 6, 2012
  3. Junio C HamanoMay 7, 2012
  4. Jeff KingMay 7, 2012
  5. Jeff KingMay 7, 2012
  6. 1/5 commit: refactor option parsingJeff King, May 7, 2012
  7. 2/5 status: refactor colopts handlingJeff King, May 7, 2012
  8. Nguyen Thai Ngoc DuyMay 8, 2012
  9. 3/5 status: refactor null_termination optionJeff King, May 7, 2012
  10. 4/5 status: fix null termination with "-b"Jeff King, May 7, 2012
  11. 5/5 status: respect "-b" for porcelain formatJeff King, May 7, 2012
  12. Jeff KingMay 7, 2012
  13. Junio C HamanoMay 8, 2012
  14. Jeff KingMay 8, 2012
  15. Junio C HamanoMay 8, 2012
  16. Junio C HamanoMay 7, 2012

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.