@matheusbsbs / matheus-bagliano / commits / 17635fc900
Fork 0

mailinfo: -b option keeps [bracketed] strings that is not a [PATCH] marker

By default, we remove leading [bracketed] [strings] from the Subject: header when coming up with the summary of the patch. This is because there are mailing lists etc that add their own headers to the subject, and they know they can add things in brackets. The most obvious example is the Linux kernel security list. Their emails look like Subject: [Security] [patch] random: make get_random_int() more random and other people mangle Subject: themselves in a similar way, e.g.: Subject: [PATCH -rc] [BUGFIX] x86: fix kernel_trap_sp() Subject: [BUGFIX][PATCH] fix bad page removal from LRU (Was Re: [RFC][PATCH] .. even though "fix" is more than enough cue to mark it as a [BUGFIX]. Some projects however want to keep these bracketed strings. With this option, we remove only [bracketed strings that contain word PATCH], so we will turn things like these [PATCH] [mailinfo] -b ... [PATCH v2] [mailinfo] -b ... [PATCH (v2) 1/4] [mailinfo] -b ... into [mailinfo] -b ... This lacks tests and integration to the "git am" toolchain to be useful, but it is a start. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jul 15, 2009 at 15:31 UTC 17635fc900674037bcaa9ca0fadcc5c23d6162e9
2 files changed +35 -21
Documentation/git-mailinfo.txt
+6 -1
@@ -8,7 +8,7 @@ git-mailinfo - Extracts patch and authorship from a single e-mail message
8
9 SYNOPSIS
10 --------
11 -'git mailinfo' [-k] [-u | --encoding=<encoding> | -n] <msg> <patch>
11 +'git mailinfo' [-k|-b] [-u | --encoding=<encoding> | -n] <msg> <patch>
12
13
14 DESCRIPTION
@@ -32,6 +32,11 @@ OPTIONS
32 munging, and is most useful when used to read back
33 'git-format-patch -k' output.
34
35 +-b::
36 + When -k is not in effect, all leading strings bracketed with '['
37 + and ']' pairs are stripped. This option limits the stripping to
38 + only the pairs whose bracketed string contains the word "PATCH".
39 +
40 -u::
41 The commit log message, author name and author email are
42 taken from the e-mail, and after minimally decoding MIME
builtin-mailinfo.c
+29 -20
@@ -10,6 +10,7 @@
10 static FILE *cmitmsg, *patchfile, *fin, *fout;
11
12 static int keep_subject;
13 +static int keep_non_patch_brackets_in_subject;
14 static const char *metainfo_charset;
15 static struct strbuf line = STRBUF_INIT;
16 static struct strbuf name = STRBUF_INIT;
@@ -219,35 +220,41 @@ static int is_multipart_boundary(const struct strbuf *line)
220
221 static void cleanup_subject(struct strbuf *subject)
222 {
222 - char *pos;
223 - size_t remove;
224 - while (subject->len) {
225 - switch (*subject->buf) {
223 + size_t at = 0;
224 +
225 + while (at < subject->len) {
226 + char *pos;
227 + size_t remove;
228 +
229 + switch (subject->buf[at]) {
230 case 'r': case 'R':
227 - if (subject->len <= 3)
231 + if (subject->len <= at + 3)
232 break;
229 - if (!memcmp(subject->buf + 1, "e:", 2)) {
230 - strbuf_remove(subject, 0, 3);
233 + if (!memcmp(subject->buf + at + 1, "e:", 2)) {
234 + strbuf_remove(subject, at, 3);
235 continue;
236 }
237 + at++;
238 break;
239 case ' ': case '\t': case ':':
235 - strbuf_remove(subject, 0, 1);
240 + strbuf_remove(subject, at, 1);
241 continue;
242 case '[':
238 - if ((pos = strchr(subject->buf, ']'))) {
239 - remove = pos - subject->buf;
240 - if (remove <= (subject->len - remove) * 2) {
241 - strbuf_remove(subject, 0, remove + 1);
242 - continue;
243 - }
244 - } else
245 - strbuf_remove(subject, 0, 1);
246 - break;
243 + pos = strchr(subject->buf + at, ']');
244 + if (!pos)
245 + break;
246 + remove = pos - subject->buf + at + 1;
247 + if (!keep_non_patch_brackets_in_subject ||
248 + (7 <= remove &&
249 + memmem(subject->buf + at, remove, "PATCH", 5)))
250 + strbuf_remove(subject, at, remove);
251 + else
252 + at += remove;
253 + continue;
254 }
248 - strbuf_trim(subject);
249 - return;
255 + break;
256 }
257 + strbuf_trim(subject);
258 }
259
260 static void cleanup_space(struct strbuf *sb)
@@ -931,7 +938,7 @@ static int mailinfo(FILE *in, FILE *out, int ks, const char *encoding,
938 }
939
940 static const char mailinfo_usage[] =
934 - "git mailinfo [-k] [-u | --encoding=<encoding> | -n] msg patch <mail >info";
941 + "git mailinfo [-k|-b] [-u | --encoding=<encoding> | -n] msg patch <mail >info";
942
943 int cmd_mailinfo(int argc, const char **argv, const char *prefix)
944 {
@@ -948,6 +955,8 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
955 while (1 < argc && argv[1][0] == '-') {
956 if (!strcmp(argv[1], "-k"))
957 keep_subject = 1;
958 + else if (!strcmp(argv[1], "-b"))
959 + keep_non_patch_brackets_in_subject = 1;
960 else if (!strcmp(argv[1], "-u"))
961 metainfo_charset = def_charset;
962 else if (!strcmp(argv[1], "-n"))