am/mailinfo: Disable scissors processing by default
You can enable it by giving --scissors to "git am". Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Aug 26, 2009 at 21:36 UTC
017678b4f47dc1b2a6691631373c46daf8f63206
10 files changed
+149
-29
Documentation/git-am.txt
+6
-11
@@ -13,7 +13,7 @@ SYNOPSIS
13
[--3way] [--interactive] [--committer-date-is-author-date]
14
[--ignore-date] [--ignore-space-change | --ignore-whitespace]
15
[--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]
16
- [--reject] [-q | --quiet]
16
+ [--reject] [-q | --quiet] [--scissors]
17
[<mbox> | <Maildir>...]
18
'git am' (--skip | --resolved | --abort)
19
@@ -39,6 +39,11 @@ OPTIONS
39
--keep::
40
Pass `-k` flag to 'git-mailinfo' (see linkgit:git-mailinfo[1]).
41
42
+-c::
43
+--scissors::
44
+ Remove everything in body before a scissors line (see
45
+ linkgit:git-mailinfo[1]).
46
+
47
-q::
48
--quiet::
49
Be quiet. Only print error messages.
@@ -128,16 +133,6 @@ the commit, after stripping common prefix "[PATCH <anything>]".
133
The "Subject: " line is supposed to concisely describe what the
134
commit is about in one line of text.
135
131
-A line that mainly consists of scissors (either ">8" or "8<") and
132
-perforation (dash "-") marks is called a scissors line, and is used to
133
-request the reader to cut the message at that line. If such a line
134
-appears in the body of the message before the patch, everything before it
135
-(including the scissors line itself) is ignored. This is useful if you
136
-want to begin your message in a discussion thread with comments and
137
-suggestions on the message you are responding to, and to conclude it with
138
-a patch submission, separating the discussion and the beginning of the
139
-proposed commit log message with a scissors line.
140
-
136
"From: " and "Subject: " lines starting the body override the respective
137
commit author name and title values taken from the headers.
138
Documentation/git-mailinfo.txt
+15
-1
@@ -8,7 +8,7 @@ git-mailinfo - Extracts patch and authorship from a single e-mail message
8
9
SYNOPSIS
10
--------
11
-'git mailinfo' [-k] [-u | --encoding=<encoding> | -n] <msg> <patch>
11
+'git mailinfo' [-k] [-u | --encoding=<encoding> | -n] [--scissors] <msg> <patch>
12
13
14
DESCRIPTION
@@ -49,6 +49,20 @@ conversion, even with this flag.
49
-n::
50
Disable all charset re-coding of the metadata.
51
52
+--scissors::
53
+ Remove everything in body before a scissors line. A line that
54
+ mainly consists of scissors (either ">8" or "8<") and perforation
55
+ (dash "-") marks is called a scissors line, and is used to request
56
+ the reader to cut the message at that line. If such a line
57
+ appears in the body of the message before the patch, everything
58
+ before it (including the scissors line itself) is ignored when
59
+ this option is used.
60
++
61
+This is useful if you want to begin your message in a discussion thread
62
+with comments and suggestions on the message you are responding to, and to
63
+conclude it with a patch submission, separating the discussion and the
64
+beginning of the proposed commit log message with a scissors line.
65
+
66
<msg>::
67
The commit log message extracted from e-mail, usually
68
except the title line which comes from e-mail Subject.
builtin-mailinfo.c
+6
-1
@@ -25,6 +25,7 @@ static enum {
25
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
30
#define MAX_HDR_PARSED 10
31
#define MAX_BOUNDARIES 5
@@ -782,7 +783,7 @@ static int handle_commit_msg(struct strbuf *line)
783
if (metainfo_charset)
784
convert_to_utf8(line, charset.buf);
785
785
- if (is_scissors_line(line)) {
786
+ if (use_scissors && is_scissors_line(line)) {
787
int i;
788
rewind(cmitmsg);
789
ftruncate(fileno(cmitmsg), 0);
@@ -1014,6 +1015,10 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
1015
metainfo_charset = NULL;
1016
else if (!prefixcmp(argv[1], "--encoding="))
1017
metainfo_charset = argv[1] + 11;
1018
+ else if (!strcmp(argv[1], "--scissors"))
1019
+ use_scissors = 1;
1020
+ else if (!strcmp(argv[1], "--no-scissors"))
1021
+ use_scissors = 0;
1022
else
1023
usage(mailinfo_usage);
1024
argc--; argv++;
git-am.sh
+17
-6
@@ -15,6 +15,7 @@ q,quiet be quiet
15
s,signoff add a Signed-off-by line to the commit message
16
u,utf8 recode into utf8 (default)
17
k,keep pass -k flag to git-mailinfo
18
+c,scissors strip everything before a scissors line
19
whitespace= pass it through git-apply
20
ignore-space-change pass it through git-apply
21
ignore-whitespace pass it through git-apply
@@ -288,7 +289,7 @@ split_patches () {
289
prec=4
290
dotest="$GIT_DIR/rebase-apply"
291
sign= utf8=t keep= skip= interactive= resolved= rebasing= abort=
291
-resolvemsg= resume=
292
+resolvemsg= resume= scissors=
293
git_apply_opt=
294
committer_date_is_author_date=
295
ignore_date=
@@ -310,6 +311,10 @@ do
311
utf8= ;;
312
-k|--keep)
313
keep=t ;;
314
+ -c|--scissors)
315
+ scissors=t ;;
316
+ --no-scissors)
317
+ scissors=f ;;
318
-r|--resolved)
319
resolved=t ;;
320
--skip)
@@ -317,7 +322,7 @@ do
322
--abort)
323
abort=t ;;
324
--rebasing)
320
- rebasing=t threeway=t keep=t ;;
325
+ rebasing=t threeway=t keep=t scissors=f ;;
326
-d|--dotest)
327
die "-d option is no longer supported. Do not use."
328
;;
@@ -435,14 +440,14 @@ else
440
441
split_patches "$@"
442
438
- # -s, -u, -k, --whitespace, -3, -C, -q and -p flags are kept
439
- # for the resuming session after a patch failure.
440
- # -i can and must be given when resuming.
443
+ # -i can and must be given when resuming; everything
444
+ # else is kept
445
echo " $git_apply_opt" >"$dotest/apply-opt"
446
echo "$threeway" >"$dotest/threeway"
447
echo "$sign" >"$dotest/sign"
448
echo "$utf8" >"$dotest/utf8"
449
echo "$keep" >"$dotest/keep"
450
+ echo "$scissors" >"$dotest/scissors"
451
echo "$GIT_QUIET" >"$dotest/quiet"
452
echo 1 >"$dotest/next"
453
if test -n "$rebasing"
@@ -484,6 +489,12 @@ if test "$(cat "$dotest/keep")" = t
489
then
490
keep=-k
491
fi
492
+case "$(cat "$dotest/scissors")" in
493
+t)
494
+ scissors=--scissors ;;
495
+f)
496
+ scissors=--no-scissors ;;
497
+esac
498
if test "$(cat "$dotest/quiet")" = t
499
then
500
GIT_QUIET=t
@@ -538,7 +549,7 @@ do
549
# by the user, or the user can tell us to do so by --resolved flag.
550
case "$resume" in
551
'')
541
- git mailinfo $keep $utf8 "$dotest/msg" "$dotest/patch" \
552
+ git mailinfo $keep $scissors $utf8 "$dotest/msg" "$dotest/patch" \
553
<"$dotest/$msgnum" >"$dotest/info" ||
554
stop_here $this
555
t/t5100-mailinfo.sh
+15
-7
@@ -13,16 +13,24 @@ test_expect_success 'split sample box' \
13
echo total is $last &&
14
test `cat last` = 14'
15
16
+check_mailinfo () {
17
+ mail=$1 opt=$2
18
+ mo="$mail$opt"
19
+ git mailinfo -u $opt msg$mo patch$mo <$mail >info$mo &&
20
+ test_cmp "$TEST_DIRECTORY"/t5100/msg$mo msg$mo &&
21
+ test_cmp "$TEST_DIRECTORY"/t5100/patch$mo patch$mo &&
22
+ test_cmp "$TEST_DIRECTORY"/t5100/info$mo info$mo
23
+}
24
+
25
+
26
for mail in `echo 00*`
27
do
28
test_expect_success "mailinfo $mail" '
19
- git mailinfo -u msg$mail patch$mail <$mail >info$mail &&
20
- echo msg &&
21
- test_cmp "$TEST_DIRECTORY"/t5100/msg$mail msg$mail &&
22
- echo patch &&
23
- test_cmp "$TEST_DIRECTORY"/t5100/patch$mail patch$mail &&
24
- echo info &&
25
- test_cmp "$TEST_DIRECTORY"/t5100/info$mail info$mail
29
+ check_mailinfo $mail "" &&
30
+ if test -f "$TEST_DIRECTORY"/t5100/msg$mail--scissors
31
+ then
32
+ check_mailinfo $mail --scissors
33
+ fi
34
'
35
done
36
t/t5100/info0014
+3
-3
@@ -1,5 +1,5 @@
1
-Author: Junio C Hamano
2
-Email: gitster@pobox.com
3
-Subject: Teach mailinfo to ignore everything before -- >8 -- mark
1
+Author: Junio Hamano
2
+Email: junkio@cox.net
3
+Subject: BLAH ONE
4
Date: Thu, 20 Aug 2009 17:18:22 -0700
5
t/t5100/info0014--scissors
new
+5
@@ -0,0 +1,5 @@
1
+Author: Junio C Hamano
2
+Email: gitster@pobox.com
3
+Subject: Teach mailinfo to ignore everything before -- >8 -- mark
4
+Date: Thu, 20 Aug 2009 17:18:22 -0700
5
+
t/t5100/msg0014
+14
@@ -1,3 +1,17 @@
1
+In real life, we will see a discussion that inspired this patch
2
+discussing related and unrelated things around >8 scissors mark
3
+in this part of the message.
4
+
5
+Subject: [PATCH] BLAH TWO
6
+
7
+And then we will see the scissors.
8
+
9
+ This line is not a scissors mark -- >8 -- but talks about it.
10
+ - - >8 - - please remove everything above this line - - >8 - -
11
+
12
+Subject: [PATCH] Teach mailinfo to ignore everything before -- >8 -- mark
13
+From: Junio C Hamano <gitster@pobox.com>
14
+
15
This teaches mailinfo the scissors -- >8 -- mark; the command ignores
16
everything before it in the message body.
17
t/t5100/msg0014--scissors
new
+4
@@ -0,0 +1,4 @@
1
+This teaches mailinfo the scissors -- >8 -- mark; the command ignores
2
+everything before it in the message body.
3
+
4
+Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t5100/patch0014--scissors
new
+64
@@ -0,0 +1,64 @@
1
+---
2
+ builtin-mailinfo.c | 37 ++++++++++++++++++++++++++++++++++++-
3
+ 1 files changed, 36 insertions(+), 1 deletions(-)
4
+
5
+diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
6
+index b0b5d8f..461c47e 100644
7
+--- a/builtin-mailinfo.c
8
++++ b/builtin-mailinfo.c
9
+@@ -712,6 +712,34 @@ static inline int patchbreak(const struct strbuf *line)
10
+ return 0;
11
+ }
12
+
13
++static int scissors(const struct strbuf *line)
14
++{
15
++ size_t i, len = line->len;
16
++ int scissors_dashes_seen = 0;
17
++ const char *buf = line->buf;
18
++
19
++ for (i = 0; i < len; i++) {
20
++ if (isspace(buf[i]))
21
++ continue;
22
++ if (buf[i] == '-') {
23
++ scissors_dashes_seen |= 02;
24
++ continue;
25
++ }
26
++ if (i + 1 < len && !memcmp(buf + i, ">8", 2)) {
27
++ scissors_dashes_seen |= 01;
28
++ i++;
29
++ continue;
30
++ }
31
++ if (i + 7 < len && !memcmp(buf + i, "cut here", 8)) {
32
++ i += 7;
33
++ continue;
34
++ }
35
++ /* everything else --- not scissors */
36
++ break;
37
++ }
38
++ return scissors_dashes_seen == 03;
39
++}
40
++
41
+ static int handle_commit_msg(struct strbuf *line)
42
+ {
43
+ static int still_looking = 1;
44
+@@ -723,10 +751,17 @@ static int handle_commit_msg(struct strbuf *line)
45
+ strbuf_ltrim(line);
46
+ if (!line->len)
47
+ return 0;
48
+- if ((still_looking = check_header(line, s_hdr_data, 0)) != 0)
49
++ still_looking = check_header(line, s_hdr_data, 0);
50
++ if (still_looking)
51
+ return 0;
52
+ }
53
+
54
++ if (scissors(line)) {
55
++ fseek(cmitmsg, 0L, SEEK_SET);
56
++ still_looking = 1;
57
++ return 0;
58
++ }
59
++
60
+ /* normalize the log message to UTF-8. */
61
+ if (metainfo_charset)
62
+ convert_to_utf8(line, charset.buf);
63
+--
64
+1.6.4.1