1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-10-31 22:37:54 +01:00

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>
This commit is contained in:
Junio C Hamano 2009-08-26 21:36:05 -07:00
parent f43c97f572
commit 017678b4f4
10 changed files with 149 additions and 29 deletions

View file

@ -13,7 +13,7 @@ SYNOPSIS
[--3way] [--interactive] [--committer-date-is-author-date]
[--ignore-date] [--ignore-space-change | --ignore-whitespace]
[--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]
[--reject] [-q | --quiet]
[--reject] [-q | --quiet] [--scissors]
[<mbox> | <Maildir>...]
'git am' (--skip | --resolved | --abort)
@ -39,6 +39,11 @@ OPTIONS
--keep::
Pass `-k` flag to 'git-mailinfo' (see linkgit:git-mailinfo[1]).
-c::
--scissors::
Remove everything in body before a scissors line (see
linkgit:git-mailinfo[1]).
-q::
--quiet::
Be quiet. Only print error messages.
@ -128,16 +133,6 @@ the commit, after stripping common prefix "[PATCH <anything>]".
The "Subject: " line is supposed to concisely describe what the
commit is about in one line of text.
A line that mainly consists of scissors (either ">8" or "8<") and
perforation (dash "-") marks is called a scissors line, and is used to
request the reader to cut the message at that line. If such a line
appears in the body of the message before the patch, everything before it
(including the scissors line itself) is ignored. This is useful if you
want to begin your message in a discussion thread with comments and
suggestions on the message you are responding to, and to conclude it with
a patch submission, separating the discussion and the beginning of the
proposed commit log message with a scissors line.
"From: " and "Subject: " lines starting the body override the respective
commit author name and title values taken from the headers.

View file

@ -8,7 +8,7 @@ git-mailinfo - Extracts patch and authorship from a single e-mail message
SYNOPSIS
--------
'git mailinfo' [-k] [-u | --encoding=<encoding> | -n] <msg> <patch>
'git mailinfo' [-k] [-u | --encoding=<encoding> | -n] [--scissors] <msg> <patch>
DESCRIPTION
@ -49,6 +49,20 @@ conversion, even with this flag.
-n::
Disable all charset re-coding of the metadata.
--scissors::
Remove everything in body before a scissors line. A line that
mainly consists of scissors (either ">8" or "8<") and perforation
(dash "-") marks is called a scissors line, and is used to request
the reader to cut the message at that line. If such a line
appears in the body of the message before the patch, everything
before it (including the scissors line itself) is ignored when
this option is used.
+
This is useful if you want to begin your message in a discussion thread
with comments and suggestions on the message you are responding to, and to
conclude it with a patch submission, separating the discussion and the
beginning of the proposed commit log message with a scissors line.
<msg>::
The commit log message extracted from e-mail, usually
except the title line which comes from e-mail Subject.

View file

@ -25,6 +25,7 @@ static enum {
static struct strbuf charset = STRBUF_INIT;
static int patch_lines;
static struct strbuf **p_hdr_data, **s_hdr_data;
static int use_scissors;
#define MAX_HDR_PARSED 10
#define MAX_BOUNDARIES 5
@ -782,7 +783,7 @@ static int handle_commit_msg(struct strbuf *line)
if (metainfo_charset)
convert_to_utf8(line, charset.buf);
if (is_scissors_line(line)) {
if (use_scissors && is_scissors_line(line)) {
int i;
rewind(cmitmsg);
ftruncate(fileno(cmitmsg), 0);
@ -1014,6 +1015,10 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
metainfo_charset = NULL;
else if (!prefixcmp(argv[1], "--encoding="))
metainfo_charset = argv[1] + 11;
else if (!strcmp(argv[1], "--scissors"))
use_scissors = 1;
else if (!strcmp(argv[1], "--no-scissors"))
use_scissors = 0;
else
usage(mailinfo_usage);
argc--; argv++;

View file

@ -15,6 +15,7 @@ q,quiet be quiet
s,signoff add a Signed-off-by line to the commit message
u,utf8 recode into utf8 (default)
k,keep pass -k flag to git-mailinfo
c,scissors strip everything before a scissors line
whitespace= pass it through git-apply
ignore-space-change pass it through git-apply
ignore-whitespace pass it through git-apply
@ -288,7 +289,7 @@ split_patches () {
prec=4
dotest="$GIT_DIR/rebase-apply"
sign= utf8=t keep= skip= interactive= resolved= rebasing= abort=
resolvemsg= resume=
resolvemsg= resume= scissors=
git_apply_opt=
committer_date_is_author_date=
ignore_date=
@ -310,6 +311,10 @@ do
utf8= ;;
-k|--keep)
keep=t ;;
-c|--scissors)
scissors=t ;;
--no-scissors)
scissors=f ;;
-r|--resolved)
resolved=t ;;
--skip)
@ -317,7 +322,7 @@ do
--abort)
abort=t ;;
--rebasing)
rebasing=t threeway=t keep=t ;;
rebasing=t threeway=t keep=t scissors=f ;;
-d|--dotest)
die "-d option is no longer supported. Do not use."
;;
@ -435,14 +440,14 @@ else
split_patches "$@"
# -s, -u, -k, --whitespace, -3, -C, -q and -p flags are kept
# for the resuming session after a patch failure.
# -i can and must be given when resuming.
# -i can and must be given when resuming; everything
# else is kept
echo " $git_apply_opt" >"$dotest/apply-opt"
echo "$threeway" >"$dotest/threeway"
echo "$sign" >"$dotest/sign"
echo "$utf8" >"$dotest/utf8"
echo "$keep" >"$dotest/keep"
echo "$scissors" >"$dotest/scissors"
echo "$GIT_QUIET" >"$dotest/quiet"
echo 1 >"$dotest/next"
if test -n "$rebasing"
@ -484,6 +489,12 @@ if test "$(cat "$dotest/keep")" = t
then
keep=-k
fi
case "$(cat "$dotest/scissors")" in
t)
scissors=--scissors ;;
f)
scissors=--no-scissors ;;
esac
if test "$(cat "$dotest/quiet")" = t
then
GIT_QUIET=t
@ -538,7 +549,7 @@ do
# by the user, or the user can tell us to do so by --resolved flag.
case "$resume" in
'')
git mailinfo $keep $utf8 "$dotest/msg" "$dotest/patch" \
git mailinfo $keep $scissors $utf8 "$dotest/msg" "$dotest/patch" \
<"$dotest/$msgnum" >"$dotest/info" ||
stop_here $this

View file

@ -13,16 +13,24 @@ test_expect_success 'split sample box' \
echo total is $last &&
test `cat last` = 14'
check_mailinfo () {
mail=$1 opt=$2
mo="$mail$opt"
git mailinfo -u $opt msg$mo patch$mo <$mail >info$mo &&
test_cmp "$TEST_DIRECTORY"/t5100/msg$mo msg$mo &&
test_cmp "$TEST_DIRECTORY"/t5100/patch$mo patch$mo &&
test_cmp "$TEST_DIRECTORY"/t5100/info$mo info$mo
}
for mail in `echo 00*`
do
test_expect_success "mailinfo $mail" '
git mailinfo -u msg$mail patch$mail <$mail >info$mail &&
echo msg &&
test_cmp "$TEST_DIRECTORY"/t5100/msg$mail msg$mail &&
echo patch &&
test_cmp "$TEST_DIRECTORY"/t5100/patch$mail patch$mail &&
echo info &&
test_cmp "$TEST_DIRECTORY"/t5100/info$mail info$mail
check_mailinfo $mail "" &&
if test -f "$TEST_DIRECTORY"/t5100/msg$mail--scissors
then
check_mailinfo $mail --scissors
fi
'
done

View file

@ -1,5 +1,5 @@
Author: Junio C Hamano
Email: gitster@pobox.com
Subject: Teach mailinfo to ignore everything before -- >8 -- mark
Author: Junio Hamano
Email: junkio@cox.net
Subject: BLAH ONE
Date: Thu, 20 Aug 2009 17:18:22 -0700

View file

@ -0,0 +1,5 @@
Author: Junio C Hamano
Email: gitster@pobox.com
Subject: Teach mailinfo to ignore everything before -- >8 -- mark
Date: Thu, 20 Aug 2009 17:18:22 -0700

View file

@ -1,3 +1,17 @@
In real life, we will see a discussion that inspired this patch
discussing related and unrelated things around >8 scissors mark
in this part of the message.
Subject: [PATCH] BLAH TWO
And then we will see the scissors.
This line is not a scissors mark -- >8 -- but talks about it.
- - >8 - - please remove everything above this line - - >8 - -
Subject: [PATCH] Teach mailinfo to ignore everything before -- >8 -- mark
From: Junio C Hamano <gitster@pobox.com>
This teaches mailinfo the scissors -- >8 -- mark; the command ignores
everything before it in the message body.

View file

@ -0,0 +1,4 @@
This teaches mailinfo the scissors -- >8 -- mark; the command ignores
everything before it in the message body.
Signed-off-by: Junio C Hamano <gitster@pobox.com>

View file

@ -0,0 +1,64 @@
---
builtin-mailinfo.c | 37 ++++++++++++++++++++++++++++++++++++-
1 files changed, 36 insertions(+), 1 deletions(-)
diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
index b0b5d8f..461c47e 100644
--- a/builtin-mailinfo.c
+++ b/builtin-mailinfo.c
@@ -712,6 +712,34 @@ static inline int patchbreak(const struct strbuf *line)
return 0;
}
+static int scissors(const struct strbuf *line)
+{
+ size_t i, len = line->len;
+ int scissors_dashes_seen = 0;
+ const char *buf = line->buf;
+
+ for (i = 0; i < len; i++) {
+ if (isspace(buf[i]))
+ continue;
+ if (buf[i] == '-') {
+ scissors_dashes_seen |= 02;
+ continue;
+ }
+ if (i + 1 < len && !memcmp(buf + i, ">8", 2)) {
+ scissors_dashes_seen |= 01;
+ i++;
+ continue;
+ }
+ if (i + 7 < len && !memcmp(buf + i, "cut here", 8)) {
+ i += 7;
+ continue;
+ }
+ /* everything else --- not scissors */
+ break;
+ }
+ return scissors_dashes_seen == 03;
+}
+
static int handle_commit_msg(struct strbuf *line)
{
static int still_looking = 1;
@@ -723,10 +751,17 @@ static int handle_commit_msg(struct strbuf *line)
strbuf_ltrim(line);
if (!line->len)
return 0;
- if ((still_looking = check_header(line, s_hdr_data, 0)) != 0)
+ still_looking = check_header(line, s_hdr_data, 0);
+ if (still_looking)
return 0;
}
+ if (scissors(line)) {
+ fseek(cmitmsg, 0L, SEEK_SET);
+ still_looking = 1;
+ return 0;
+ }
+
/* normalize the log message to UTF-8. */
if (metainfo_charset)
convert_to_utf8(line, charset.buf);
--
1.6.4.1