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>
Paolo Bonzini committed
Nov 25, 2014 at 15:00 UTC
452dfbed1a80754bfdc52567d9d9dba08a7d0a6d
6 files changed
+73
-1
Documentation/git-mailinfo.txt
+5
@@ -66,6 +66,11 @@ conversion, even with this flag.
66
-n::
67
Disable all charset re-coding of the metadata.
68
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
+
74
--scissors::
75
Remove everything in body before a scissors line. A line that
76
mainly consists of scissors (either ">8" or "8<") and perforation
builtin/mailinfo.c
+21
-1
@@ -15,6 +15,7 @@ static const char *metainfo_charset;
15
static struct strbuf line = STRBUF_INIT;
16
static struct strbuf name = STRBUF_INIT;
17
static struct strbuf email = STRBUF_INIT;
18
+static char *message_id;
19
20
static enum {
21
TE_DONTCARE, TE_QP, TE_BASE64
@@ -24,6 +25,7 @@ static struct strbuf charset = STRBUF_INIT;
25
static int patch_lines;
26
static struct strbuf **p_hdr_data, **s_hdr_data;
27
static int use_scissors;
28
+static int add_message_id;
29
static int use_inbody_headers = 1;
30
31
#define MAX_HDR_PARSED 10
@@ -198,6 +200,12 @@ static void handle_content_type(struct strbuf *line)
200
}
201
}
202
203
+static void handle_message_id(const struct strbuf *line)
204
+{
205
+ if (add_message_id)
206
+ message_id = strdup(line->buf);
207
+}
208
+
209
static void handle_content_transfer_encoding(const struct strbuf *line)
210
{
211
if (strcasestr(line->buf, "base64"))
@@ -342,6 +350,14 @@ static int check_header(const struct strbuf *line,
350
ret = 1;
351
goto check_header_out;
352
}
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
+ }
361
362
/* for inbody stuff */
363
if (starts_with(line->buf, ">From") && isspace(line->buf[5])) {
@@ -816,6 +832,8 @@ static int handle_commit_msg(struct strbuf *line)
832
}
833
834
if (patchbreak(line)) {
835
+ if (message_id)
836
+ fprintf(cmitmsg, "Message-Id: %s\n", message_id);
837
fclose(cmitmsg);
838
cmitmsg = NULL;
839
return 1;
@@ -1013,7 +1031,7 @@ static int git_mailinfo_config(const char *var, const char *value, void *unused)
1031
}
1032
1033
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";
1035
1036
int cmd_mailinfo(int argc, const char **argv, const char *prefix)
1037
{
@@ -1032,6 +1050,8 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
1050
keep_subject = 1;
1051
else if (!strcmp(argv[1], "-b"))
1052
keep_non_patch_brackets_in_subject = 1;
1053
+ else if (!strcmp(argv[1], "-m") || !strcmp(argv[1], "--message-id"))
1054
+ add_message_id = 1;
1055
else if (!strcmp(argv[1], "-u"))
1056
metainfo_charset = def_charset;
1057
else if (!strcmp(argv[1], "-n"))
t/t5100-mailinfo.sh
+4
@@ -35,6 +35,10 @@ do
35
then
36
check_mailinfo $mail --no-inbody-headers
37
fi
38
+ if test -f "$TEST_DIRECTORY"/t5100/msg$mail--message-id
39
+ then
40
+ check_mailinfo $mail --message-id
41
+ fi
42
'
43
done
44
t/t5100/info0012--message-id
new
+5
@@ -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
new
+8
@@ -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
new
+30
@@ -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