Skip to content

Commit 452dfbe

Browse files
bonzinigitster
authored andcommitted
git-mailinfo: add --message-id
This option adds the content of the Message-Id header at the end of the commit message prepared by git-mailinfo. This is useful in order to associate commit messages automatically with mailing list discussions. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 652e759 commit 452dfbe

File tree

6 files changed

+73
-1
lines changed

6 files changed

+73
-1
lines changed

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"))

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)