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

Re: [PATCH] log-tree: use custom line terminator in line termination mode

From
Junio C Hamano <gitster@pobox.com>
Date
May 1, 2012, 17:06 UTC
Message-ID
<7vobq7al12.fsf@alter.siamese.dyndns.org>
In-Reply-To
<7v1un3c23p.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
Show 25 quoted lines
> Jeff King <peff@peff.net> writes:
>
>> Hmm. This came up before, and the issue is (or can be) slightly more
>> complex:
>>
>>   http://thread.gmane.org/gmane.comp.version-control.git/122478/focus=122568
>
> Yeah, the test given completely forgets about "log -p" case, as you said
> in the above:
>
>     But we can't just modify that to use the specified line terminator,
>     because sometimes it is acting as a separator between commit message and
>     diff, and sometimes it is acting as the terminator of the whole record.
>
> So the patch is not quite right for the "log -p -z" (or "log --stat -z")
> case.
>
> The correct output would have NUL after each commit, so "-z --format=%s"
> would have a single-liner subject with the line-terminating LF replaced
> with NUL, and "-p/--stat -z --format=%s" would have a single-liner subject
> with its line-terminating LF, followed by the diff/diffstat in which the
> terminating LF of the last line is replaced with NUL, but to be consistent
> with what "-p/--stat -z --pretty=format:%s" does, I think it is OK to
> append NUL to the diff/diffstat part instead of replacing its last LF with
> NUL.

In other words, this test on top (the last one only demonstrates the breakage).

 t/t4205-log-pretty-formats.sh |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)
diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh
index f00e446..4afd778 100755
--- a/t/t4205-log-pretty-formats.sh
+++ b/t/t4205-log-pretty-formats.sh
@@ -83,4 +83,20 @@ test_expect_success 'NUL termination' '
 	test_cmp expected actual
 '
 
+test_expect_success 'NUL separation with --stat' '
+	stat0_part=$(git diff --stat HEAD^ HEAD) &&
+	stat1_part=$(git diff --stat --root HEAD^) &&
+	printf "add bar\n$stat0_part\n\0initial\n$stat1_part\n" >expected &&
+	git log -z --stat --pretty="format:%s" >actual &&
+	test_cmp expected actual
+'
+
+test_expect_failure 'NUL termination with --stat' '
+	stat0_part=$(git diff --stat HEAD^ HEAD) &&
+	stat1_part=$(git diff --stat --root HEAD^) &&
+	printf "add bar\n$stat0_part\n\0initial\n$stat1_part\n\0" >expected &&
+	git log -z --stat --pretty="tformat:%s" >actual &&
+	test_cmp expected actual
+'
+
 test_done
Previous: Junio C HamanoNext: Junio C Hamano
Message 16 of 17 in “git log -z still outputting newlines?”
  1. Randal L. SchwartzApr 30, 2012
  2. Andreas SchwabApr 30, 2012
  3. Thomas RastApr 30, 2012
  4. log-tree: use custom line terminator in line termination modeJan Krüger, Apr 30, 2012
  5. Junio C HamanoApr 30, 2012
  6. log-tree: use custom line terminator in line termination modeJan Krüger, Apr 30, 2012
  7. Junio C HamanoApr 30, 2012
  8. Jan KrügerApr 30, 2012
  9. Andreas SchwabMay 1, 2012
  10. Junio C HamanoMay 1, 2012
  11. Andreas SchwabMay 1, 2012
  12. Randal L. SchwartzMay 1, 2012
  13. Junio C HamanoMay 1, 2012
  14. Jeff KingMay 1, 2012
  15. Junio C HamanoMay 1, 2012
  16. Junio C HamanoMay 1, 2012
  17. Junio C HamanoMay 1, 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.