OSDN Git Service

commit.c: make find_commit_subject() more robust
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Wed, 22 Jun 2016 20:20:20 +0000 (22:20 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 22 Jun 2016 20:24:17 +0000 (13:24 -0700)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
commit.c
t/t8008-blame-formats.sh

index 0eee410..116774c 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -398,7 +398,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
index 29f84a6..92c8e79 100755 (executable)
@@ -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