Skip to content

Commit fa7f51d

Browse files
committed
Merge branch 'pb/am-message-id-footer'
"git am" learned "--message-id" option to copy the message ID of the incoming e-mail to the log message of resulting commit. * pb/am-message-id-footer: git-am: add --message-id/--no-message-id git-mailinfo: add --message-id
2 parents a7ddaa8 + a078f73 commit fa7f51d

9 files changed

Lines changed: 126 additions & 3 deletions

File tree

Documentation/git-am.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ OPTIONS
5757
--no-scissors::
5858
Ignore scissors lines (see linkgit:git-mailinfo[1]).
5959

60+
-m::
61+
--message-id::
62+
Pass the `-m` flag to 'git mailinfo' (see linkgit:git-mailinfo[1]),
63+
so that the Message-ID header is added to the commit message.
64+
The `am.messageid` configuration variable can be used to specify
65+
the default behaviour.
66+
67+
--no-message-id::
68+
Do not add the Message-ID header to the commit message.
69+
`no-message-id` is useful to override `am.messageid`.
70+
6071
-q::
6172
--quiet::
6273
Be quiet. Only print error messages.

Documentation/git-mailinfo.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ conversion, even with this flag.
6666
-n::
6767
Disable all charset re-coding of the metadata.
6868

69+
-m::
70+
--message-id::
71+
Copy the Message-ID header at the end of the commit message. This
72+
is useful in order to associate commits with mailing list discussions.
73+
6974
--scissors::
7075
Remove everything in body before a scissors line. A line that
7176
mainly consists of scissors (either ">8" or "8<") and perforation

builtin/mailinfo.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ static const char *metainfo_charset;
1515
static struct strbuf line = STRBUF_INIT;
1616
static struct strbuf name = STRBUF_INIT;
1717
static struct strbuf email = STRBUF_INIT;
18+
static char *message_id;
1819

1920
static enum {
2021
TE_DONTCARE, TE_QP, TE_BASE64
@@ -24,6 +25,7 @@ static struct strbuf charset = STRBUF_INIT;
2425
static int patch_lines;
2526
static struct strbuf **p_hdr_data, **s_hdr_data;
2627
static int use_scissors;
28+
static int add_message_id;
2729
static int use_inbody_headers = 1;
2830

2931
#define MAX_HDR_PARSED 10
@@ -198,6 +200,12 @@ static void handle_content_type(struct strbuf *line)
198200
}
199201
}
200202

203+
static void handle_message_id(const struct strbuf *line)
204+
{
205+
if (add_message_id)
206+
message_id = strdup(line->buf);
207+
}
208+
201209
static void handle_content_transfer_encoding(const struct strbuf *line)
202210
{
203211
if (strcasestr(line->buf, "base64"))
@@ -342,6 +350,14 @@ static int check_header(const struct strbuf *line,
342350
ret = 1;
343351
goto check_header_out;
344352
}
353+
if (cmp_header(line, "Message-Id")) {
354+
len = strlen("Message-Id: ");
355+
strbuf_add(&sb, line->buf + len, line->len - len);
356+
decode_header(&sb);
357+
handle_message_id(&sb);
358+
ret = 1;
359+
goto check_header_out;
360+
}
345361

346362
/* for inbody stuff */
347363
if (starts_with(line->buf, ">From") && isspace(line->buf[5])) {
@@ -816,6 +832,8 @@ static int handle_commit_msg(struct strbuf *line)
816832
}
817833

818834
if (patchbreak(line)) {
835+
if (message_id)
836+
fprintf(cmitmsg, "Message-Id: %s\n", message_id);
819837
fclose(cmitmsg);
820838
cmitmsg = NULL;
821839
return 1;
@@ -1013,7 +1031,7 @@ static int git_mailinfo_config(const char *var, const char *value, void *unused)
10131031
}
10141032

10151033
static const char mailinfo_usage[] =
1016-
"git mailinfo [-k|-b] [-u | --encoding=<encoding> | -n] [--scissors | --no-scissors] msg patch < mail >info";
1034+
"git mailinfo [-k|-b] [-m | --message-id] [-u | --encoding=<encoding> | -n] [--scissors | --no-scissors] msg patch < mail >info";
10171035

10181036
int cmd_mailinfo(int argc, const char **argv, const char *prefix)
10191037
{
@@ -1032,6 +1050,8 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
10321050
keep_subject = 1;
10331051
else if (!strcmp(argv[1], "-b"))
10341052
keep_non_patch_brackets_in_subject = 1;
1053+
else if (!strcmp(argv[1], "-m") || !strcmp(argv[1], "--message-id"))
1054+
add_message_id = 1;
10351055
else if (!strcmp(argv[1], "-u"))
10361056
metainfo_charset = def_charset;
10371057
else if (!strcmp(argv[1], "-n"))

git-am.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ s,signoff add a Signed-off-by line to the commit message
1717
u,utf8 recode into utf8 (default)
1818
k,keep pass -k flag to git-mailinfo
1919
keep-non-patch pass -b flag to git-mailinfo
20+
m,message-id pass -m flag to git-mailinfo
2021
keep-cr pass --keep-cr flag to git-mailsplit for mbox format
2122
no-keep-cr do not pass --keep-cr flag to git-mailsplit independent of am.keepcr
2223
c,scissors strip everything before a scissors line
@@ -371,13 +372,18 @@ split_patches () {
371372
prec=4
372373
dotest="$GIT_DIR/rebase-apply"
373374
sign= utf8=t keep= keepcr= skip= interactive= resolved= rebasing= abort=
374-
resolvemsg= resume= scissors= no_inbody_headers=
375+
messageid= resolvemsg= resume= scissors= no_inbody_headers=
375376
git_apply_opt=
376377
committer_date_is_author_date=
377378
ignore_date=
378379
allow_rerere_autoupdate=
379380
gpg_sign_opt=
380381

382+
if test "$(git config --bool --get am.messageid)" = true
383+
then
384+
messageid=t
385+
fi
386+
381387
if test "$(git config --bool --get am.keepcr)" = true
382388
then
383389
keepcr=t
@@ -400,6 +406,10 @@ it will be removed. Please do not use it anymore."
400406
utf8=t ;; # this is now default
401407
--no-utf8)
402408
utf8= ;;
409+
-m|--message-id)
410+
messageid=t ;;
411+
--no-message-id)
412+
messageid=f ;;
403413
-k|--keep)
404414
keep=t ;;
405415
--keep-non-patch)
@@ -567,6 +577,7 @@ Use \"git am --abort\" to remove it.")"
567577
echo "$sign" >"$dotest/sign"
568578
echo "$utf8" >"$dotest/utf8"
569579
echo "$keep" >"$dotest/keep"
580+
echo "$messageid" >"$dotest/messageid"
570581
echo "$scissors" >"$dotest/scissors"
571582
echo "$no_inbody_headers" >"$dotest/no_inbody_headers"
572583
echo "$GIT_QUIET" >"$dotest/quiet"
@@ -621,6 +632,12 @@ b)
621632
*)
622633
keep= ;;
623634
esac
635+
case "$(cat "$dotest/messageid")" in
636+
t)
637+
messageid=-m ;;
638+
f)
639+
messageid= ;;
640+
esac
624641
case "$(cat "$dotest/scissors")" in
625642
t)
626643
scissors=--scissors ;;
@@ -692,7 +709,7 @@ do
692709
get_author_ident_from_commit "$commit" >"$dotest/author-script"
693710
git diff-tree --root --binary --full-index "$commit" >"$dotest/patch"
694711
else
695-
git mailinfo $keep $no_inbody_headers $scissors $utf8 "$dotest/msg" "$dotest/patch" \
712+
git mailinfo $keep $no_inbody_headers $messageid $scissors $utf8 "$dotest/msg" "$dotest/patch" \
696713
<"$dotest/$msgnum" >"$dotest/info" ||
697714
stop_here $this
698715

t/t4150-am.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ test_expect_success setup '
8585
8686
git format-patch --stdout first >patch1 &&
8787
{
88+
echo "Message-Id: <1226501681-24923-1-git-send-email-bda@mnsspb.ru>" &&
8889
echo "X-Fake-Field: Line One" &&
8990
echo "X-Fake-Field: Line Two" &&
9091
echo "X-Fake-Field: Line Three" &&
@@ -536,4 +537,26 @@ test_expect_success 'am empty-file does not infloop' '
536537
test_i18ncmp expected actual
537538
'
538539

540+
test_expect_success 'am --message-id really adds the message id' '
541+
rm -fr .git/rebase-apply &&
542+
git reset --hard &&
543+
git checkout HEAD^ &&
544+
git am --message-id patch1.eml &&
545+
test_path_is_missing .git/rebase-apply &&
546+
git cat-file commit HEAD | tail -n1 >actual &&
547+
grep Message-Id patch1.eml >expected &&
548+
test_cmp expected actual
549+
'
550+
551+
test_expect_success 'am --message-id -s signs off after the message id' '
552+
rm -fr .git/rebase-apply &&
553+
git reset --hard &&
554+
git checkout HEAD^ &&
555+
git am -s --message-id patch1.eml &&
556+
test_path_is_missing .git/rebase-apply &&
557+
git cat-file commit HEAD | tail -n2 | head -n1 >actual &&
558+
grep Message-Id patch1.eml >expected &&
559+
test_cmp expected actual
560+
'
561+
539562
test_done

t/t5100-mailinfo.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ do
3535
then
3636
check_mailinfo $mail --no-inbody-headers
3737
fi
38+
if test -f "$TEST_DIRECTORY"/t5100/msg$mail--message-id
39+
then
40+
check_mailinfo $mail --message-id
41+
fi
3842
'
3943
done
4044

t/t5100/info0012--message-id

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Author: Dmitriy Blinov
2+
Email: bda@mnsspb.ru
3+
Subject: Изменён список пакетов необходимых для сборки
4+
Date: Wed, 12 Nov 2008 17:54:41 +0300
5+

t/t5100/msg0012--message-id

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
textlive-* исправлены на texlive-*
2+
docutils заменён на python-docutils
3+
4+
Действительно, оказалось, что rest2web вытягивает за собой
5+
python-docutils. В то время как сам rest2web не нужен.
6+
7+
Signed-off-by: Dmitriy Blinov <bda@mnsspb.ru>
8+
Message-Id: <1226501681-24923-1-git-send-email-bda@mnsspb.ru>

t/t5100/patch0012--message-id

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
howto/build_navy.txt | 6 +++---
3+
1 files changed, 3 insertions(+), 3 deletions(-)
4+
5+
diff --git a/howto/build_navy.txt b/howto/build_navy.txt
6+
index 3fd3afb..0ee807e 100644
7+
--- a/howto/build_navy.txt
8+
+++ b/howto/build_navy.txt
9+
@@ -119,8 +119,8 @@
10+
- libxv-dev
11+
- libusplash-dev
12+
- latex-make
13+
- - textlive-lang-cyrillic
14+
- - textlive-latex-extra
15+
+ - texlive-lang-cyrillic
16+
+ - texlive-latex-extra
17+
- dia
18+
- python-pyrex
19+
- libtool
20+
@@ -128,7 +128,7 @@
21+
- sox
22+
- cython
23+
- imagemagick
24+
- - docutils
25+
+ - python-docutils
26+
27+
#. на машине dinar: добавить свой открытый ssh-ключ в authorized_keys2 пользователя ddev
28+
#. на своей машине: отредактировать /etc/sudoers (команда ``visudo``) примерно следующим образом::
29+
--
30+
1.5.6.5

0 commit comments

Comments
 (0)