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

[PATCH v4 2/2] Make find_commit_subject() more robust

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jun 22, 2016, 20:20 UTC
Message-ID
<40e7a90edbb66b3523e19832e13ee10bc96b0371.1466626795.git.johannes.schindelin@gmx.de>
In-Reply-To
<cover.1466626795.git.johannes.schindelin@gmx.de>

Just like the pretty printing machinery, we should simply ignore blank lines at the beginning of the commit messages.

This discrepancy was noticed when an early version of the rebase--helper produced commit objects with more than one empty line between the header and the commit message.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 commit.c                 |  2 +-
 t/t8008-blame-formats.sh | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/commit.c b/commit.c
index 3f4f371..24d4715 100644
--- a/commit.c
+++ b/commit.c
@@ -414,7 +414,7 @@ int find_commit_subject(const char *commit_buffer, const char **subject)
 	while (*p && (*p != '\n' || p[1] != '\n'))
 		p++;
 	if (*p) {
-		p += 2;
+		p = skip_blank_lines(p + 2);
 		for (eol = p; *eol && *eol != '\n'; eol++)
 			; /* do nothing */
 	} else
diff --git a/t/t8008-blame-formats.sh b/t/t8008-blame-formats.sh
index 29f84a6..92c8e79 100755
--- a/t/t8008-blame-formats.sh
+++ b/t/t8008-blame-formats.sh
@@ -87,4 +87,21 @@ test_expect_success 'blame --line-porcelain output' '
 	test_cmp expect actual
 '
 
+test_expect_success '--porcelain detects first non-blank line as subject' '
+	(
+		GIT_INDEX_FILE=.git/tmp-index &&
+		export GIT_INDEX_FILE &&
+		echo "This is it" >single-file &&
+		git add single-file &&
+		tree=$(git write-tree) &&
+		commit=$(printf "%s\n%s\n%s\n\n\n  \noneline\n\nbody\n" \
+			"tree $tree" \
+			"author A <a@b.c> 123456789 +0000" \
+			"committer C <c@d.e> 123456789 +0000" |
+		git hash-object -w -t commit --stdin) &&
+		git blame --porcelain $commit -- single-file >output &&
+		grep "^summary oneline$" output
+	)
+'
+
 test_done
-- 
2.9.0.118.g0e1a633
Previous: Johannes Schindelin
Message 15 of 15 in “Make find_commit_subject() more robust”
  1. Make find_commit_subject() more robustJohannes Schindelin, Jun 18, 2016
  2. Junio C HamanoJun 20, 2016
  3. Johannes SchindelinJun 21, 2016
  4. Junio C HamanoJun 21, 2016
  5. Johannes SchindelinJun 22, 2016
  6. Make find_commit_subject() more robustJohannes Schindelin, Jun 21, 2016
  7. Junio C HamanoJun 21, 2016
  8. 0/2 Make find_commit_subject() consistent with --format=%sJohannes Schindelin, Jun 22, 2016
  9. 2/2 Make find_commit_subject() more robustJohannes Schindelin, Jun 22, 2016
  10. 1/2 Make the skip_empty_lines() function publicJohannes Schindelin, Jun 22, 2016
  11. Junio C HamanoJun 22, 2016
  12. Johannes SchindelinJun 22, 2016
  13. 0/2 Make find_commit_subject() consistent with --format=%sJohannes Schindelin, Jun 22, 2016
  14. 1/2 Make the skip_blank_lines() function publicJohannes Schindelin, Jun 22, 2016
  15. 2/2 Make find_commit_subject() more robustJohannes Schindelin, Jun 22, 2016

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.