git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Zak Johnson <zakj@nox.cx>
Subject: [PATCH 4/5] status: fix null termination with "-b"
Date: Mon, 7 May 2012 17:24:38 -0400	[thread overview]
Message-ID: <20120507212438.GD19567@sigill.intra.peff.net> (raw)
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

  parent reply	other threads:[~2012-05-07 21:24 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-06 13:29 [PATCH] correct git-status Porcelain Format documentation Jeff King
2012-05-06 13:51 ` Jeff King
2012-05-07 18:10   ` Junio C Hamano
2012-05-07 18:13     ` Jeff King
2012-05-07 21:21       ` Jeff King
2012-05-07 21:22         ` [PATCH 1/5] commit: refactor option parsing Jeff King
2012-05-07 21:23         ` [PATCH 2/5] status: refactor colopts handling Jeff King
2012-05-08 13:27           ` Nguyen Thai Ngoc Duy
2012-05-07 21:24         ` [PATCH 3/5] status: refactor null_termination option Jeff King
2012-05-07 21:24         ` Jeff King [this message]
2012-05-07 21:25         ` [PATCH 5/5] status: respect "-b" for porcelain format Jeff King
2012-05-07 21:28           ` Jeff King
2012-05-08  4:55             ` Junio C Hamano
2012-05-08  9:04               ` Jeff King
2012-05-08 17:52                 ` Junio C Hamano
2012-05-07 18:03 ` [PATCH] correct git-status Porcelain Format documentation Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120507212438.GD19567@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=zakj@nox.cx \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).