mailinfo: fix in-body header continuations
authorLinus Torvalds <torvalds@linux-foundation.org>
Sat, 1 Apr 2017 19:14:39 +0000 (12:14 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 11 Apr 2017 07:49:40 +0000 (00:49 -0700)
An empty line should stop any pending in-body headers, and start the
actual body parsing.

This also modifies the original test for the in-body headers to actually
have a real commit body that starts with spaces, and changes the test to
check that the long line matches _exactly_, and doesn't get extra data
from the body.

Fixes:6b4b013f1884 ("mailinfo: handle in-body header continuations")
Cc: Jonathan Tan <jonathantanmy@google.com>
Cc: Jeff King <peff@peff.net>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
mailinfo.c
t/t4150-am.sh
index 2275b285f097d632e38d7f1fe59692df1f807e28..1e4e28309941ae7207950e626c46932b32003c71 100644 (file)
@@ -674,8 +674,13 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
        assert(!mi->filter_stage);
 
        if (mi->header_stage) {
-               if (!line->len || (line->len == 1 && line->buf[0] == '\n'))
+               if (!line->len || (line->len == 1 && line->buf[0] == '\n')) {
+                       if (mi->inbody_header_accum.len) {
+                               flush_inbody_header_accum(mi);
+                               mi->header_stage = 0;
+                       }
                        return 0;
+               }
        }
 
        if (mi->use_inbody_headers && mi->header_stage) {
index 89a5bacac5ad069ec10b16bfdf3dbde7217cf4de..44807e218d7016f58bd41b89af71104a37f31a8b 100755 (executable)
@@ -983,7 +983,9 @@ test_expect_success 'am works with multi-line in-body headers' '
        rm -fr .git/rebase-apply &&
        git checkout -f first &&
        echo one >> file &&
-       git commit -am "$LONG" --author="$LONG <long@example.com>" &&
+       git commit -am "$LONG
+
+    Body test" --author="$LONG <long@example.com>" &&
        git format-patch --stdout -1 >patch &&
        # bump from, date, and subject down to in-body header
        perl -lpe "
@@ -997,7 +999,7 @@ test_expect_success 'am works with multi-line in-body headers' '
        git am msg &&
        # Ensure that the author and full message are present
        git cat-file commit HEAD | grep "^author.*long@example.com" &&
-       git cat-file commit HEAD | grep "^$LONG"
+       git cat-file commit HEAD | grep "^$LONG$"
 '
 
 test_done