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>
This commit is contained in:
parent
78d553b7d7
commit
d25e51596b
@ -26,6 +26,7 @@ static struct strbuf charset = STRBUF_INIT;
|
|||||||
static int patch_lines;
|
static int patch_lines;
|
||||||
static struct strbuf **p_hdr_data, **s_hdr_data;
|
static struct strbuf **p_hdr_data, **s_hdr_data;
|
||||||
static int use_scissors;
|
static int use_scissors;
|
||||||
|
static int use_inbody_headers = 1;
|
||||||
|
|
||||||
#define MAX_HDR_PARSED 10
|
#define MAX_HDR_PARSED 10
|
||||||
#define MAX_BOUNDARIES 5
|
#define MAX_BOUNDARIES 5
|
||||||
@ -774,10 +775,17 @@ static int handle_commit_msg(struct strbuf *line)
|
|||||||
strbuf_ltrim(line);
|
strbuf_ltrim(line);
|
||||||
if (!line->len)
|
if (!line->len)
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (use_inbody_headers && still_looking) {
|
||||||
still_looking = check_header(line, s_hdr_data, 0);
|
still_looking = check_header(line, s_hdr_data, 0);
|
||||||
if (still_looking)
|
if (still_looking)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
} else
|
||||||
|
/* Only trim the first (blank) line of the commit message
|
||||||
|
* when ignoring in-body headers.
|
||||||
|
*/
|
||||||
|
still_looking = 0;
|
||||||
|
|
||||||
/* normalize the log message to UTF-8. */
|
/* normalize the log message to UTF-8. */
|
||||||
if (metainfo_charset)
|
if (metainfo_charset)
|
||||||
@ -1033,6 +1041,8 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
|
|||||||
use_scissors = 1;
|
use_scissors = 1;
|
||||||
else if (!strcmp(argv[1], "--no-scissors"))
|
else if (!strcmp(argv[1], "--no-scissors"))
|
||||||
use_scissors = 0;
|
use_scissors = 0;
|
||||||
|
else if (!strcmp(argv[1], "--no-inbody-headers"))
|
||||||
|
use_inbody_headers = 0;
|
||||||
else
|
else
|
||||||
usage(mailinfo_usage);
|
usage(mailinfo_usage);
|
||||||
argc--; argv++;
|
argc--; argv++;
|
||||||
|
13
git-am.sh
13
git-am.sh
@ -289,7 +289,7 @@ split_patches () {
|
|||||||
prec=4
|
prec=4
|
||||||
dotest="$GIT_DIR/rebase-apply"
|
dotest="$GIT_DIR/rebase-apply"
|
||||||
sign= utf8=t keep= skip= interactive= resolved= rebasing= abort=
|
sign= utf8=t keep= skip= interactive= resolved= rebasing= abort=
|
||||||
resolvemsg= resume= scissors=
|
resolvemsg= resume= scissors= no_inbody_headers=
|
||||||
git_apply_opt=
|
git_apply_opt=
|
||||||
committer_date_is_author_date=
|
committer_date_is_author_date=
|
||||||
ignore_date=
|
ignore_date=
|
||||||
@ -322,7 +322,7 @@ do
|
|||||||
--abort)
|
--abort)
|
||||||
abort=t ;;
|
abort=t ;;
|
||||||
--rebasing)
|
--rebasing)
|
||||||
rebasing=t threeway=t keep=t scissors=f ;;
|
rebasing=t threeway=t keep=t scissors=f no_inbody_headers=t ;;
|
||||||
-d|--dotest)
|
-d|--dotest)
|
||||||
die "-d option is no longer supported. Do not use."
|
die "-d option is no longer supported. Do not use."
|
||||||
;;
|
;;
|
||||||
@ -448,6 +448,7 @@ else
|
|||||||
echo "$utf8" >"$dotest/utf8"
|
echo "$utf8" >"$dotest/utf8"
|
||||||
echo "$keep" >"$dotest/keep"
|
echo "$keep" >"$dotest/keep"
|
||||||
echo "$scissors" >"$dotest/scissors"
|
echo "$scissors" >"$dotest/scissors"
|
||||||
|
echo "$no_inbody_headers" >"$dotest/no_inbody_headers"
|
||||||
echo "$GIT_QUIET" >"$dotest/quiet"
|
echo "$GIT_QUIET" >"$dotest/quiet"
|
||||||
echo 1 >"$dotest/next"
|
echo 1 >"$dotest/next"
|
||||||
if test -n "$rebasing"
|
if test -n "$rebasing"
|
||||||
@ -495,6 +496,12 @@ t)
|
|||||||
f)
|
f)
|
||||||
scissors=--no-scissors ;;
|
scissors=--no-scissors ;;
|
||||||
esac
|
esac
|
||||||
|
if test "$(cat "$dotest/no_inbody_headers")" = t
|
||||||
|
then
|
||||||
|
no_inbody_headers=--no-inbody-headers
|
||||||
|
else
|
||||||
|
no_inbody_headers=
|
||||||
|
fi
|
||||||
if test "$(cat "$dotest/quiet")" = t
|
if test "$(cat "$dotest/quiet")" = t
|
||||||
then
|
then
|
||||||
GIT_QUIET=t
|
GIT_QUIET=t
|
||||||
@ -549,7 +556,7 @@ do
|
|||||||
# by the user, or the user can tell us to do so by --resolved flag.
|
# by the user, or the user can tell us to do so by --resolved flag.
|
||||||
case "$resume" in
|
case "$resume" in
|
||||||
'')
|
'')
|
||||||
git mailinfo $keep $scissors $utf8 "$dotest/msg" "$dotest/patch" \
|
git mailinfo $keep $no_inbody_headers $scissors $utf8 "$dotest/msg" "$dotest/patch" \
|
||||||
<"$dotest/$msgnum" >"$dotest/info" ||
|
<"$dotest/$msgnum" >"$dotest/info" ||
|
||||||
stop_here $this
|
stop_here $this
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ test_expect_success 'split sample box' \
|
|||||||
'git mailsplit -o. "$TEST_DIRECTORY"/t5100/sample.mbox >last &&
|
'git mailsplit -o. "$TEST_DIRECTORY"/t5100/sample.mbox >last &&
|
||||||
last=`cat last` &&
|
last=`cat last` &&
|
||||||
echo total is $last &&
|
echo total is $last &&
|
||||||
test `cat last` = 14'
|
test `cat last` = 16'
|
||||||
|
|
||||||
check_mailinfo () {
|
check_mailinfo () {
|
||||||
mail=$1 opt=$2
|
mail=$1 opt=$2
|
||||||
@ -30,6 +30,10 @@ do
|
|||||||
if test -f "$TEST_DIRECTORY"/t5100/msg$mail--scissors
|
if test -f "$TEST_DIRECTORY"/t5100/msg$mail--scissors
|
||||||
then
|
then
|
||||||
check_mailinfo $mail --scissors
|
check_mailinfo $mail --scissors
|
||||||
|
fi &&
|
||||||
|
if test -f "$TEST_DIRECTORY"/t5100/msg$mail--no-inbody-headers
|
||||||
|
then
|
||||||
|
check_mailinfo $mail --no-inbody-headers
|
||||||
fi
|
fi
|
||||||
'
|
'
|
||||||
done
|
done
|
||||||
|
5
t/t5100/info0015
Normal file
5
t/t5100/info0015
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
Author:
|
||||||
|
Email:
|
||||||
|
Subject: check bogus body header (from)
|
||||||
|
Date: Fri, 9 Jun 2006 00:44:16 -0700
|
||||||
|
|
5
t/t5100/info0015--no-inbody-headers
Normal file
5
t/t5100/info0015--no-inbody-headers
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
Author: A U Thor
|
||||||
|
Email: a.u.thor@example.com
|
||||||
|
Subject: check bogus body header (from)
|
||||||
|
Date: Fri, 9 Jun 2006 00:44:16 -0700
|
||||||
|
|
5
t/t5100/info0016
Normal file
5
t/t5100/info0016
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
Author: A U Thor
|
||||||
|
Email: a.u.thor@example.com
|
||||||
|
Subject: check bogus body header (date)
|
||||||
|
Date: bogus
|
||||||
|
|
5
t/t5100/info0016--no-inbody-headers
Normal file
5
t/t5100/info0016--no-inbody-headers
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
Author: A U Thor
|
||||||
|
Email: a.u.thor@example.com
|
||||||
|
Subject: check bogus body header (date)
|
||||||
|
Date: Fri, 9 Jun 2006 00:44:16 -0700
|
||||||
|
|
2
t/t5100/msg0015
Normal file
2
t/t5100/msg0015
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
- a list
|
||||||
|
- of stuff
|
3
t/t5100/msg0015--no-inbody-headers
Normal file
3
t/t5100/msg0015--no-inbody-headers
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
From: bogosity
|
||||||
|
- a list
|
||||||
|
- of stuff
|
2
t/t5100/msg0016
Normal file
2
t/t5100/msg0016
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
and some content
|
||||||
|
|
4
t/t5100/msg0016--no-inbody-headers
Normal file
4
t/t5100/msg0016--no-inbody-headers
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
Date: bogus
|
||||||
|
|
||||||
|
and some content
|
||||||
|
|
8
t/t5100/patch0015
Normal file
8
t/t5100/patch0015
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
diff --git a/foo b/foo
|
||||||
|
index e69de29..d95f3ad 100644
|
||||||
|
--- a/foo
|
||||||
|
+++ b/foo
|
||||||
|
@@ -0,0 +1 @@
|
||||||
|
+content
|
||||||
|
|
8
t/t5100/patch0015--no-inbody-headers
Normal file
8
t/t5100/patch0015--no-inbody-headers
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
diff --git a/foo b/foo
|
||||||
|
index e69de29..d95f3ad 100644
|
||||||
|
--- a/foo
|
||||||
|
+++ b/foo
|
||||||
|
@@ -0,0 +1 @@
|
||||||
|
+content
|
||||||
|
|
8
t/t5100/patch0016
Normal file
8
t/t5100/patch0016
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
diff --git a/foo b/foo
|
||||||
|
index e69de29..d95f3ad 100644
|
||||||
|
--- a/foo
|
||||||
|
+++ b/foo
|
||||||
|
@@ -0,0 +1 @@
|
||||||
|
+content
|
||||||
|
|
8
t/t5100/patch0016--no-inbody-headers
Normal file
8
t/t5100/patch0016--no-inbody-headers
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
diff --git a/foo b/foo
|
||||||
|
index e69de29..d95f3ad 100644
|
||||||
|
--- a/foo
|
||||||
|
+++ b/foo
|
||||||
|
@@ -0,0 +1 @@
|
||||||
|
+content
|
||||||
|
|
@ -650,3 +650,36 @@ index b0b5d8f..461c47e 100644
|
|||||||
convert_to_utf8(line, charset.buf);
|
convert_to_utf8(line, charset.buf);
|
||||||
--
|
--
|
||||||
1.6.4.1
|
1.6.4.1
|
||||||
|
From nobody Mon Sep 17 00:00:00 2001
|
||||||
|
From: A U Thor <a.u.thor@example.com>
|
||||||
|
Subject: check bogus body header (from)
|
||||||
|
Date: Fri, 9 Jun 2006 00:44:16 -0700
|
||||||
|
|
||||||
|
From: bogosity
|
||||||
|
- a list
|
||||||
|
- of stuff
|
||||||
|
---
|
||||||
|
diff --git a/foo b/foo
|
||||||
|
index e69de29..d95f3ad 100644
|
||||||
|
--- a/foo
|
||||||
|
+++ b/foo
|
||||||
|
@@ -0,0 +1 @@
|
||||||
|
+content
|
||||||
|
|
||||||
|
From nobody Mon Sep 17 00:00:00 2001
|
||||||
|
From: A U Thor <a.u.thor@example.com>
|
||||||
|
Subject: check bogus body header (date)
|
||||||
|
Date: Fri, 9 Jun 2006 00:44:16 -0700
|
||||||
|
|
||||||
|
Date: bogus
|
||||||
|
|
||||||
|
and some content
|
||||||
|
|
||||||
|
---
|
||||||
|
diff --git a/foo b/foo
|
||||||
|
index e69de29..d95f3ad 100644
|
||||||
|
--- a/foo
|
||||||
|
+++ b/foo
|
||||||
|
@@ -0,0 +1 @@
|
||||||
|
+content
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user