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

[take 2] Clean up "git log" format with DIFF_FORMAT_NO_OUTPUT

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Oct 9, 2007, 16:35 UTC
Message-ID
<alpine.LFD.0.999.0710090932560.5039@woody.linux-foundation.org>
In-Reply-To
<alpine.LFD.0.999.0710081353290.4964@woody.linux-foundation.org>
Clean up "git log" format with DIFF_FORMAT_NO_OUTPUT

This fixes an unnecessary empty line that we add to the log message when we generate diffs, but don't actually end up printing any due to having DIFF_FORMAT_NO_OUTPUT set.

This can happen with pickaxe or with rename following. The reason is that we normally add an empty line between the commit and the diff, but we do that even for the case where we've then suppressed the actual printing of the diff.

This also updates a couple of tests that assumed the extraneous empty line would exist at the end of output.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---

This is a resend of the original patch, with just the changes to the tests added to make it pass them all. Both of the tests actually got cleaner, I think (ie one had the sed script blindly just delete the last line in order to match it up with the known input, for example).

			Linus
 log-tree.c                  |    3 ++-
 t/t3900-i18n-commit.sh      |    2 +-
 t/t4013/diff.log_-SF_master |    1 -
 3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/log-tree.c b/log-tree.c
index 2319154..62edd34 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -304,7 +304,8 @@ int log_tree_diff_flush(struct rev_info *opt)
 		 * output for readability.
 		 */
 		show_log(opt, opt->diffopt.msg_sep);
-		if (opt->verbose_header &&
+		if ((opt->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT) &&
+		    opt->verbose_header &&
 		    opt->commit_format != CMIT_FMT_ONELINE) {
 			int pch = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH;
 			if ((pch & opt->diffopt.output_format) == pch)
diff --git a/t/t3900-i18n-commit.sh b/t/t3900-i18n-commit.sh
index fcbabe8..94b1c24 100755
--- a/t/t3900-i18n-commit.sh
+++ b/t/t3900-i18n-commit.sh
@@ -8,7 +8,7 @@ test_description='commit and log output encodings'
 . ./test-lib.sh
 
 compare_with () {
-	git show -s $1 | sed -e '1,/^$/d' -e 's/^    //' -e '$d' >current &&
+	git show -s $1 | sed -e '1,/^$/d' -e 's/^    //' >current &&
 	git diff current "$2"
 }
 
diff --git a/t/t4013/diff.log_-SF_master b/t/t4013/diff.log_-SF_master
index 6162ed2..c1599f2 100644
--- a/t/t4013/diff.log_-SF_master
+++ b/t/t4013/diff.log_-SF_master
@@ -4,5 +4,4 @@ Author: A U Thor <author@example.com>
 Date:   Mon Jun 26 00:02:00 2006 +0000
 
     Third
-
 $
Previous: Linus Torvalds
Message 4 of 4 in “Fix embarrassing "git log --follow" bug”
  1. Linus TorvaldsOct 8, 2007
  2. Clean up "git log" format with DIFF_FORMAT_NO_OUTPUTLinus Torvalds, Oct 8, 2007
  3. Linus TorvaldsOct 8, 2007
  4. [take 2] Clean up "git log" format with DIFF_FORMAT_NO_OUTPUTLinus Torvalds, Oct 9, 2007

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.