mailinfo: fix in-body header continuations

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>

Linus Torvalds committed Apr 1, 2017 at 12:14 UTC fd1062e52e1a7ed3be443a320708ed849958c1bf
2 files changed +10 -3
mailinfo.c
+6 -1
@@ -674,8 +674,13 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
674 assert(!mi->filter_stage);
675
676 if (mi->header_stage) {
677 - if (!line->len || (line->len == 1 && line->buf[0] == '\n'))
677 + if (!line->len || (line->len == 1 && line->buf[0] == '\n')) {
678 + if (mi->inbody_header_accum.len) {
679 + flush_inbody_header_accum(mi);
680 + mi->header_stage = 0;
681 + }
682 return 0;
683 + }
684 }
685
686 if (mi->use_inbody_headers && mi->header_stage) {
t/t4150-am.sh
+4 -2
@@ -983,7 +983,9 @@ test_expect_success 'am works with multi-line in-body headers' '
983 rm -fr .git/rebase-apply &&
984 git checkout -f first &&
985 echo one >> file &&
986 - git commit -am "$LONG" --author="$LONG <long@example.com>" &&
986 + git commit -am "$LONG
987 +
988 + Body test" --author="$LONG <long@example.com>" &&
989 git format-patch --stdout -1 >patch &&
990 # bump from, date, and subject down to in-body header
991 perl -lpe "
@@ -997,7 +999,7 @@ test_expect_success 'am works with multi-line in-body headers' '
999 git am msg &&
1000 # Ensure that the author and full message are present
1001 git cat-file commit HEAD | grep "^author.*long@example.com" &&
1000 - git cat-file commit HEAD | grep "^$LONG"
1002 + git cat-file commit HEAD | grep "^$LONG$"
1003 '
1004
1005 test_done