@matheusbsbs / matheus-bagliano / commits / d25e51596b
Fork 0

git am/mailinfo: Don't look at in-body headers when rebasing

When we are rebasing we know that the header lines in the patch are good and that we don't need to pick up any headers from the body of the patch. This makes it possible to rebase commits whose commit message start with "From" or "Date". Test vectors by Jeff King. Signed-off-by: Lukas Sandström <luksan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Lukas Sandström committed Nov 20, 2009 at 17:12 UTC d25e51596be9271ad833805a3d6f9012dc24ee79
16 files changed +122 -5
builtin-mailinfo.c
+11 -1
@@ -26,6 +26,7 @@ static struct strbuf charset = STRBUF_INIT;
26 static int patch_lines;
27 static struct strbuf **p_hdr_data, **s_hdr_data;
28 static int use_scissors;
29 +static int use_inbody_headers = 1;
30
31 #define MAX_HDR_PARSED 10
32 #define MAX_BOUNDARIES 5
@@ -774,10 +775,17 @@ static int handle_commit_msg(struct strbuf *line)
775 strbuf_ltrim(line);
776 if (!line->len)
777 return 0;
778 + }
779 +
780 + if (use_inbody_headers && still_looking) {
781 still_looking = check_header(line, s_hdr_data, 0);
782 if (still_looking)
783 return 0;
780 - }
784 + } else
785 + /* Only trim the first (blank) line of the commit message
786 + * when ignoring in-body headers.
787 + */
788 + still_looking = 0;
789
790 /* normalize the log message to UTF-8. */
791 if (metainfo_charset)
@@ -1033,6 +1041,8 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
1041 use_scissors = 1;
1042 else if (!strcmp(argv[1], "--no-scissors"))
1043 use_scissors = 0;
1044 + else if (!strcmp(argv[1], "--no-inbody-headers"))
1045 + use_inbody_headers = 0;
1046 else
1047 usage(mailinfo_usage);
1048 argc--; argv++;
git-am.sh
+10 -3
@@ -289,7 +289,7 @@ split_patches () {
289 prec=4
290 dotest="$GIT_DIR/rebase-apply"
291 sign= utf8=t keep= skip= interactive= resolved= rebasing= abort=
292 -resolvemsg= resume= scissors=
292 +resolvemsg= resume= scissors= no_inbody_headers=
293 git_apply_opt=
294 committer_date_is_author_date=
295 ignore_date=
@@ -322,7 +322,7 @@ do
322 --abort)
323 abort=t ;;
324 --rebasing)
325 - rebasing=t threeway=t keep=t scissors=f ;;
325 + rebasing=t threeway=t keep=t scissors=f no_inbody_headers=t ;;
326 -d|--dotest)
327 die "-d option is no longer supported. Do not use."
328 ;;
@@ -448,6 +448,7 @@ else
448 echo "$utf8" >"$dotest/utf8"
449 echo "$keep" >"$dotest/keep"
450 echo "$scissors" >"$dotest/scissors"
451 + echo "$no_inbody_headers" >"$dotest/no_inbody_headers"
452 echo "$GIT_QUIET" >"$dotest/quiet"
453 echo 1 >"$dotest/next"
454 if test -n "$rebasing"
@@ -495,6 +496,12 @@ t)
496 f)
497 scissors=--no-scissors ;;
498 esac
499 +if test "$(cat "$dotest/no_inbody_headers")" = t
500 +then
501 + no_inbody_headers=--no-inbody-headers
502 +else
503 + no_inbody_headers=
504 +fi
505 if test "$(cat "$dotest/quiet")" = t
506 then
507 GIT_QUIET=t
@@ -549,7 +556,7 @@ do
556 # by the user, or the user can tell us to do so by --resolved flag.
557 case "$resume" in
558 '')
552 - git mailinfo $keep $scissors $utf8 "$dotest/msg" "$dotest/patch" \
559 + git mailinfo $keep $no_inbody_headers $scissors $utf8 "$dotest/msg" "$dotest/patch" \
560 <"$dotest/$msgnum" >"$dotest/info" ||
561 stop_here $this
562
t/t5100-mailinfo.sh
+5 -1
@@ -11,7 +11,7 @@ test_expect_success 'split sample box' \
11 'git mailsplit -o. "$TEST_DIRECTORY"/t5100/sample.mbox >last &&
12 last=`cat last` &&
13 echo total is $last &&
14 - test `cat last` = 14'
14 + test `cat last` = 16'
15
16 check_mailinfo () {
17 mail=$1 opt=$2
@@ -30,6 +30,10 @@ do
30 if test -f "$TEST_DIRECTORY"/t5100/msg$mail--scissors
31 then
32 check_mailinfo $mail --scissors
33 + fi &&
34 + if test -f "$TEST_DIRECTORY"/t5100/msg$mail--no-inbody-headers
35 + then
36 + check_mailinfo $mail --no-inbody-headers
37 fi
38 '
39 done
t/t5100/info0015 new
+5
@@ -0,0 +1,5 @@
1 +Author:
2 +Email:
3 +Subject: check bogus body header (from)
4 +Date: Fri, 9 Jun 2006 00:44:16 -0700
5 +
t/t5100/info0015--no-inbody-headers new
+5
@@ -0,0 +1,5 @@
1 +Author: A U Thor
2 +Email: a.u.thor@example.com
3 +Subject: check bogus body header (from)
4 +Date: Fri, 9 Jun 2006 00:44:16 -0700
5 +
t/t5100/info0016 new
+5
@@ -0,0 +1,5 @@
1 +Author: A U Thor
2 +Email: a.u.thor@example.com
3 +Subject: check bogus body header (date)
4 +Date: bogus
5 +
t/t5100/info0016--no-inbody-headers new
+5
@@ -0,0 +1,5 @@
1 +Author: A U Thor
2 +Email: a.u.thor@example.com
3 +Subject: check bogus body header (date)
4 +Date: Fri, 9 Jun 2006 00:44:16 -0700
5 +
t/t5100/msg0015 new
+2
@@ -0,0 +1,2 @@
1 +- a list
2 + - of stuff
t/t5100/msg0015--no-inbody-headers new
+3
@@ -0,0 +1,3 @@
1 +From: bogosity
2 + - a list
3 + - of stuff
t/t5100/msg0016 new
+2
@@ -0,0 +1,2 @@
1 +and some content
2 +
t/t5100/msg0016--no-inbody-headers new
+4
@@ -0,0 +1,4 @@
1 +Date: bogus
2 +
3 +and some content
4 +
t/t5100/patch0015 new
+8
@@ -0,0 +1,8 @@
1 +---
2 +diff --git a/foo b/foo
3 +index e69de29..d95f3ad 100644
4 +--- a/foo
5 ++++ b/foo
6 +@@ -0,0 +1 @@
7 ++content
8 +
t/t5100/patch0015--no-inbody-headers new
+8
@@ -0,0 +1,8 @@
1 +---
2 +diff --git a/foo b/foo
3 +index e69de29..d95f3ad 100644
4 +--- a/foo
5 ++++ b/foo
6 +@@ -0,0 +1 @@
7 ++content
8 +
t/t5100/patch0016 new
+8
@@ -0,0 +1,8 @@
1 +---
2 +diff --git a/foo b/foo
3 +index e69de29..d95f3ad 100644
4 +--- a/foo
5 ++++ b/foo
6 +@@ -0,0 +1 @@
7 ++content
8 +
t/t5100/patch0016--no-inbody-headers new
+8
@@ -0,0 +1,8 @@
1 +---
2 +diff --git a/foo b/foo
3 +index e69de29..d95f3ad 100644
4 +--- a/foo
5 ++++ b/foo
6 +@@ -0,0 +1 @@
7 ++content
8 +
t/t5100/sample.mbox
+33
@@ -650,3 +650,36 @@ index b0b5d8f..461c47e 100644
650 convert_to_utf8(line, charset.buf);
651 --
652 1.6.4.1
653 +From nobody Mon Sep 17 00:00:00 2001
654 +From: A U Thor <a.u.thor@example.com>
655 +Subject: check bogus body header (from)
656 +Date: Fri, 9 Jun 2006 00:44:16 -0700
657 +
658 +From: bogosity
659 + - a list
660 + - of stuff
661 +---
662 +diff --git a/foo b/foo
663 +index e69de29..d95f3ad 100644
664 +--- a/foo
665 ++++ b/foo
666 +@@ -0,0 +1 @@
667 ++content
668 +
669 +From nobody Mon Sep 17 00:00:00 2001
670 +From: A U Thor <a.u.thor@example.com>
671 +Subject: check bogus body header (date)
672 +Date: Fri, 9 Jun 2006 00:44:16 -0700
673 +
674 +Date: bogus
675 +
676 +and some content
677 +
678 +---
679 +diff --git a/foo b/foo
680 +index e69de29..d95f3ad 100644
681 +--- a/foo
682 ++++ b/foo
683 +@@ -0,0 +1 @@
684 ++content
685 +