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:
parent
f43c97f572
commit
017678b4f4
10 changed files with 149 additions and 29 deletions
|
@ -13,7 +13,7 @@ SYNOPSIS
|
||||||
[--3way] [--interactive] [--committer-date-is-author-date]
|
[--3way] [--interactive] [--committer-date-is-author-date]
|
||||||
[--ignore-date] [--ignore-space-change | --ignore-whitespace]
|
[--ignore-date] [--ignore-space-change | --ignore-whitespace]
|
||||||
[--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]
|
[--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]
|
||||||
[--reject] [-q | --quiet]
|
[--reject] [-q | --quiet] [--scissors]
|
||||||
[<mbox> | <Maildir>...]
|
[<mbox> | <Maildir>...]
|
||||||
'git am' (--skip | --resolved | --abort)
|
'git am' (--skip | --resolved | --abort)
|
||||||
|
|
||||||
|
@ -39,6 +39,11 @@ OPTIONS
|
||||||
--keep::
|
--keep::
|
||||||
Pass `-k` flag to 'git-mailinfo' (see linkgit:git-mailinfo[1]).
|
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::
|
-q::
|
||||||
--quiet::
|
--quiet::
|
||||||
Be quiet. Only print error messages.
|
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
|
The "Subject: " line is supposed to concisely describe what the
|
||||||
commit is about in one line of text.
|
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
|
"From: " and "Subject: " lines starting the body override the respective
|
||||||
commit author name and title values taken from the headers.
|
commit author name and title values taken from the headers.
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ git-mailinfo - Extracts patch and authorship from a single e-mail message
|
||||||
|
|
||||||
SYNOPSIS
|
SYNOPSIS
|
||||||
--------
|
--------
|
||||||
'git mailinfo' [-k] [-u | --encoding=<encoding> | -n] <msg> <patch>
|
'git mailinfo' [-k] [-u | --encoding=<encoding> | -n] [--scissors] <msg> <patch>
|
||||||
|
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
|
@ -49,6 +49,20 @@ conversion, even with this flag.
|
||||||
-n::
|
-n::
|
||||||
Disable all charset re-coding of the metadata.
|
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>::
|
<msg>::
|
||||||
The commit log message extracted from e-mail, usually
|
The commit log message extracted from e-mail, usually
|
||||||
except the title line which comes from e-mail Subject.
|
except the title line which comes from e-mail Subject.
|
||||||
|
|
|
@ -25,6 +25,7 @@ static enum {
|
||||||
static struct strbuf charset = STRBUF_INIT;
|
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;
|
||||||
|
|
||||||
#define MAX_HDR_PARSED 10
|
#define MAX_HDR_PARSED 10
|
||||||
#define MAX_BOUNDARIES 5
|
#define MAX_BOUNDARIES 5
|
||||||
|
@ -782,7 +783,7 @@ static int handle_commit_msg(struct strbuf *line)
|
||||||
if (metainfo_charset)
|
if (metainfo_charset)
|
||||||
convert_to_utf8(line, charset.buf);
|
convert_to_utf8(line, charset.buf);
|
||||||
|
|
||||||
if (is_scissors_line(line)) {
|
if (use_scissors && is_scissors_line(line)) {
|
||||||
int i;
|
int i;
|
||||||
rewind(cmitmsg);
|
rewind(cmitmsg);
|
||||||
ftruncate(fileno(cmitmsg), 0);
|
ftruncate(fileno(cmitmsg), 0);
|
||||||
|
@ -1014,6 +1015,10 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
|
||||||
metainfo_charset = NULL;
|
metainfo_charset = NULL;
|
||||||
else if (!prefixcmp(argv[1], "--encoding="))
|
else if (!prefixcmp(argv[1], "--encoding="))
|
||||||
metainfo_charset = argv[1] + 11;
|
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
|
else
|
||||||
usage(mailinfo_usage);
|
usage(mailinfo_usage);
|
||||||
argc--; argv++;
|
argc--; argv++;
|
||||||
|
|
23
git-am.sh
23
git-am.sh
|
@ -15,6 +15,7 @@ q,quiet be quiet
|
||||||
s,signoff add a Signed-off-by line to the commit message
|
s,signoff add a Signed-off-by line to the commit message
|
||||||
u,utf8 recode into utf8 (default)
|
u,utf8 recode into utf8 (default)
|
||||||
k,keep pass -k flag to git-mailinfo
|
k,keep pass -k flag to git-mailinfo
|
||||||
|
c,scissors strip everything before a scissors line
|
||||||
whitespace= pass it through git-apply
|
whitespace= pass it through git-apply
|
||||||
ignore-space-change pass it through git-apply
|
ignore-space-change pass it through git-apply
|
||||||
ignore-whitespace pass it through git-apply
|
ignore-whitespace pass it through git-apply
|
||||||
|
@ -288,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=
|
resolvemsg= resume= scissors=
|
||||||
git_apply_opt=
|
git_apply_opt=
|
||||||
committer_date_is_author_date=
|
committer_date_is_author_date=
|
||||||
ignore_date=
|
ignore_date=
|
||||||
|
@ -310,6 +311,10 @@ do
|
||||||
utf8= ;;
|
utf8= ;;
|
||||||
-k|--keep)
|
-k|--keep)
|
||||||
keep=t ;;
|
keep=t ;;
|
||||||
|
-c|--scissors)
|
||||||
|
scissors=t ;;
|
||||||
|
--no-scissors)
|
||||||
|
scissors=f ;;
|
||||||
-r|--resolved)
|
-r|--resolved)
|
||||||
resolved=t ;;
|
resolved=t ;;
|
||||||
--skip)
|
--skip)
|
||||||
|
@ -317,7 +322,7 @@ do
|
||||||
--abort)
|
--abort)
|
||||||
abort=t ;;
|
abort=t ;;
|
||||||
--rebasing)
|
--rebasing)
|
||||||
rebasing=t threeway=t keep=t ;;
|
rebasing=t threeway=t keep=t scissors=f ;;
|
||||||
-d|--dotest)
|
-d|--dotest)
|
||||||
die "-d option is no longer supported. Do not use."
|
die "-d option is no longer supported. Do not use."
|
||||||
;;
|
;;
|
||||||
|
@ -435,14 +440,14 @@ else
|
||||||
|
|
||||||
split_patches "$@"
|
split_patches "$@"
|
||||||
|
|
||||||
# -s, -u, -k, --whitespace, -3, -C, -q and -p flags are kept
|
# -i can and must be given when resuming; everything
|
||||||
# for the resuming session after a patch failure.
|
# else is kept
|
||||||
# -i can and must be given when resuming.
|
|
||||||
echo " $git_apply_opt" >"$dotest/apply-opt"
|
echo " $git_apply_opt" >"$dotest/apply-opt"
|
||||||
echo "$threeway" >"$dotest/threeway"
|
echo "$threeway" >"$dotest/threeway"
|
||||||
echo "$sign" >"$dotest/sign"
|
echo "$sign" >"$dotest/sign"
|
||||||
echo "$utf8" >"$dotest/utf8"
|
echo "$utf8" >"$dotest/utf8"
|
||||||
echo "$keep" >"$dotest/keep"
|
echo "$keep" >"$dotest/keep"
|
||||||
|
echo "$scissors" >"$dotest/scissors"
|
||||||
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"
|
||||||
|
@ -484,6 +489,12 @@ if test "$(cat "$dotest/keep")" = t
|
||||||
then
|
then
|
||||||
keep=-k
|
keep=-k
|
||||||
fi
|
fi
|
||||||
|
case "$(cat "$dotest/scissors")" in
|
||||||
|
t)
|
||||||
|
scissors=--scissors ;;
|
||||||
|
f)
|
||||||
|
scissors=--no-scissors ;;
|
||||||
|
esac
|
||||||
if test "$(cat "$dotest/quiet")" = t
|
if test "$(cat "$dotest/quiet")" = t
|
||||||
then
|
then
|
||||||
GIT_QUIET=t
|
GIT_QUIET=t
|
||||||
|
@ -538,7 +549,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 $utf8 "$dotest/msg" "$dotest/patch" \
|
git mailinfo $keep $scissors $utf8 "$dotest/msg" "$dotest/patch" \
|
||||||
<"$dotest/$msgnum" >"$dotest/info" ||
|
<"$dotest/$msgnum" >"$dotest/info" ||
|
||||||
stop_here $this
|
stop_here $this
|
||||||
|
|
||||||
|
|
|
@ -13,16 +13,24 @@ test_expect_success 'split sample box' \
|
||||||
echo total is $last &&
|
echo total is $last &&
|
||||||
test `cat last` = 14'
|
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*`
|
for mail in `echo 00*`
|
||||||
do
|
do
|
||||||
test_expect_success "mailinfo $mail" '
|
test_expect_success "mailinfo $mail" '
|
||||||
git mailinfo -u msg$mail patch$mail <$mail >info$mail &&
|
check_mailinfo $mail "" &&
|
||||||
echo msg &&
|
if test -f "$TEST_DIRECTORY"/t5100/msg$mail--scissors
|
||||||
test_cmp "$TEST_DIRECTORY"/t5100/msg$mail msg$mail &&
|
then
|
||||||
echo patch &&
|
check_mailinfo $mail --scissors
|
||||||
test_cmp "$TEST_DIRECTORY"/t5100/patch$mail patch$mail &&
|
fi
|
||||||
echo info &&
|
|
||||||
test_cmp "$TEST_DIRECTORY"/t5100/info$mail info$mail
|
|
||||||
'
|
'
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
Author: Junio C Hamano
|
Author: Junio Hamano
|
||||||
Email: gitster@pobox.com
|
Email: junkio@cox.net
|
||||||
Subject: Teach mailinfo to ignore everything before -- >8 -- mark
|
Subject: BLAH ONE
|
||||||
Date: Thu, 20 Aug 2009 17:18:22 -0700
|
Date: Thu, 20 Aug 2009 17:18:22 -0700
|
||||||
|
|
||||||
|
|
5
t/t5100/info0014--scissors
Normal file
5
t/t5100/info0014--scissors
Normal 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
|
||||||
|
|
|
@ -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
|
This teaches mailinfo the scissors -- >8 -- mark; the command ignores
|
||||||
everything before it in the message body.
|
everything before it in the message body.
|
||||||
|
|
||||||
|
|
4
t/t5100/msg0014--scissors
Normal file
4
t/t5100/msg0014--scissors
Normal 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>
|
64
t/t5100/patch0014--scissors
Normal file
64
t/t5100/patch0014--scissors
Normal 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
|
Loading…
Reference in a new issue