Skip to content

Commit 017678b

Browse files
committed
am/mailinfo: Disable scissors processing by default
You can enable it by giving --scissors to "git am". Signed-off-by: Junio C Hamano <[email protected]>
1 parent f43c97f commit 017678b

File tree

10 files changed

+149
-29
lines changed

10 files changed

+149
-29
lines changed

Documentation/git-am.txt

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ SYNOPSIS
1313
[--3way] [--interactive] [--committer-date-is-author-date]
1414
[--ignore-date] [--ignore-space-change | --ignore-whitespace]
1515
[--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]
16-
[--reject] [-q | --quiet]
16+
[--reject] [-q | --quiet] [--scissors]
1717
[<mbox> | <Maildir>...]
1818
'git am' (--skip | --resolved | --abort)
1919

@@ -39,6 +39,11 @@ OPTIONS
3939
--keep::
4040
Pass `-k` flag to 'git-mailinfo' (see linkgit:git-mailinfo[1]).
4141

42+
-c::
43+
--scissors::
44+
Remove everything in body before a scissors line (see
45+
linkgit:git-mailinfo[1]).
46+
4247
-q::
4348
--quiet::
4449
Be quiet. Only print error messages.
@@ -128,16 +133,6 @@ the commit, after stripping common prefix "[PATCH <anything>]".
128133
The "Subject: " line is supposed to concisely describe what the
129134
commit is about in one line of text.
130135

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-
141136
"From: " and "Subject: " lines starting the body override the respective
142137
commit author name and title values taken from the headers.
143138

Documentation/git-mailinfo.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ git-mailinfo - Extracts patch and authorship from a single e-mail message
88

99
SYNOPSIS
1010
--------
11-
'git mailinfo' [-k] [-u | --encoding=<encoding> | -n] <msg> <patch>
11+
'git mailinfo' [-k] [-u | --encoding=<encoding> | -n] [--scissors] <msg> <patch>
1212

1313

1414
DESCRIPTION
@@ -49,6 +49,20 @@ conversion, even with this flag.
4949
-n::
5050
Disable all charset re-coding of the metadata.
5151

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+
5266
<msg>::
5367
The commit log message extracted from e-mail, usually
5468
except the title line which comes from e-mail Subject.

builtin-mailinfo.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ static enum {
2525
static struct strbuf charset = STRBUF_INIT;
2626
static int patch_lines;
2727
static struct strbuf **p_hdr_data, **s_hdr_data;
28+
static int use_scissors;
2829

2930
#define MAX_HDR_PARSED 10
3031
#define MAX_BOUNDARIES 5
@@ -782,7 +783,7 @@ static int handle_commit_msg(struct strbuf *line)
782783
if (metainfo_charset)
783784
convert_to_utf8(line, charset.buf);
784785

785-
if (is_scissors_line(line)) {
786+
if (use_scissors && is_scissors_line(line)) {
786787
int i;
787788
rewind(cmitmsg);
788789
ftruncate(fileno(cmitmsg), 0);
@@ -1014,6 +1015,10 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
10141015
metainfo_charset = NULL;
10151016
else if (!prefixcmp(argv[1], "--encoding="))
10161017
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;
10171022
else
10181023
usage(mailinfo_usage);
10191024
argc--; argv++;

git-am.sh

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ q,quiet be quiet
1515
s,signoff add a Signed-off-by line to the commit message
1616
u,utf8 recode into utf8 (default)
1717
k,keep pass -k flag to git-mailinfo
18+
c,scissors strip everything before a scissors line
1819
whitespace= pass it through git-apply
1920
ignore-space-change pass it through git-apply
2021
ignore-whitespace pass it through git-apply
@@ -288,7 +289,7 @@ split_patches () {
288289
prec=4
289290
dotest="$GIT_DIR/rebase-apply"
290291
sign= utf8=t keep= skip= interactive= resolved= rebasing= abort=
291-
resolvemsg= resume=
292+
resolvemsg= resume= scissors=
292293
git_apply_opt=
293294
committer_date_is_author_date=
294295
ignore_date=
@@ -310,14 +311,18 @@ do
310311
utf8= ;;
311312
-k|--keep)
312313
keep=t ;;
314+
-c|--scissors)
315+
scissors=t ;;
316+
--no-scissors)
317+
scissors=f ;;
313318
-r|--resolved)
314319
resolved=t ;;
315320
--skip)
316321
skip=t ;;
317322
--abort)
318323
abort=t ;;
319324
--rebasing)
320-
rebasing=t threeway=t keep=t ;;
325+
rebasing=t threeway=t keep=t scissors=f ;;
321326
-d|--dotest)
322327
die "-d option is no longer supported. Do not use."
323328
;;
@@ -435,14 +440,14 @@ else
435440

436441
split_patches "$@"
437442

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
441445
echo " $git_apply_opt" >"$dotest/apply-opt"
442446
echo "$threeway" >"$dotest/threeway"
443447
echo "$sign" >"$dotest/sign"
444448
echo "$utf8" >"$dotest/utf8"
445449
echo "$keep" >"$dotest/keep"
450+
echo "$scissors" >"$dotest/scissors"
446451
echo "$GIT_QUIET" >"$dotest/quiet"
447452
echo 1 >"$dotest/next"
448453
if test -n "$rebasing"
@@ -484,6 +489,12 @@ if test "$(cat "$dotest/keep")" = t
484489
then
485490
keep=-k
486491
fi
492+
case "$(cat "$dotest/scissors")" in
493+
t)
494+
scissors=--scissors ;;
495+
f)
496+
scissors=--no-scissors ;;
497+
esac
487498
if test "$(cat "$dotest/quiet")" = t
488499
then
489500
GIT_QUIET=t
@@ -538,7 +549,7 @@ do
538549
# by the user, or the user can tell us to do so by --resolved flag.
539550
case "$resume" in
540551
'')
541-
git mailinfo $keep $utf8 "$dotest/msg" "$dotest/patch" \
552+
git mailinfo $keep $scissors $utf8 "$dotest/msg" "$dotest/patch" \
542553
<"$dotest/$msgnum" >"$dotest/info" ||
543554
stop_here $this
544555

t/t5100-mailinfo.sh

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,24 @@ test_expect_success 'split sample box' \
1313
echo total is $last &&
1414
test `cat last` = 14'
1515

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+
1626
for mail in `echo 00*`
1727
do
1828
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
2634
'
2735
done
2836

t/t5100/info0014

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Author: Junio C Hamano
2-
3-
Subject: Teach mailinfo to ignore everything before -- >8 -- mark
1+
Author: Junio Hamano
2+
3+
Subject: BLAH ONE
44
Date: Thu, 20 Aug 2009 17:18:22 -0700
55

t/t5100/info0014--scissors

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Author: Junio C Hamano
2+
3+
Subject: Teach mailinfo to ignore everything before -- >8 -- mark
4+
Date: Thu, 20 Aug 2009 17:18:22 -0700
5+

t/t5100/msg0014

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 <[email protected]>
14+
115
This teaches mailinfo the scissors -- >8 -- mark; the command ignores
216
everything before it in the message body.
317

t/t5100/msg0014--scissors

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 <[email protected]>

t/t5100/patch0014--scissors

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)