Thread (1 message) 1 message, 1 author, 2016-06-21

Re: [PATCH v2] Make find_commit_subject() more robust

From: Junio C Hamano <hidden>
Date: 2016-06-21 20:42:07

Johannes Schindelin [off-list ref] writes:
Just like the pretty printing machinery, we should simply ignore empty
lines at the beginning of the commit messages.
Thanks.
quoted hunk
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 <redacted>
---
Published-As: https://github.com/dscho/git/releases/tag/leading-empty-lines-v2

	git blame seemed to be the most accessible user of
	find_commit_subject()...

 commit.c                 |  2 ++
 t/t8008-blame-formats.sh | 17 +++++++++++++++++
 2 files changed, 19 insertions(+)
Interdiff vs v1:

 diff --git a/t/t8008-blame-formats.sh b/t/t8008-blame-formats.sh
 index 29f84a6..03bd313 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-empty 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\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

diff --git a/commit.c b/commit.c
index 3f4f371..7b00989 100644
--- a/commit.c
+++ b/commit.c
@@ -415,6 +415,8 @@ int find_commit_subject(const char *commit_buffer, const char **subject)
 		p++;
 	if (*p) {
 		p += 2;
+		while (*p == '\n')
+			p++;
 		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..03bd313 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-empty 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\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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help