Skip to content

Commit d268cb9

Browse files
committed
Merge branch 'jc/mailinfo-remove-brackets'
Conflicts: Documentation/git-mailinfo.txt builtin-mailinfo.c
2 parents 0c7cc13 + 17635fc commit d268cb9

File tree

2 files changed

+35
-21
lines changed

2 files changed

+35
-21
lines changed

Documentation/git-mailinfo.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ git-mailinfo - Extracts patch and authorship from a single e-mail message
88

99
SYNOPSIS
1010
--------
11-
'git mailinfo' [-k] [-u | --encoding=<encoding> | -n] [--scissors] <msg> <patch>
11+
'git mailinfo' [-k|-b] [-u | --encoding=<encoding> | -n] [--scissors] <msg> <patch>
1212

1313

1414
DESCRIPTION
@@ -32,6 +32,11 @@ OPTIONS
3232
munging, and is most useful when used to read back
3333
'git-format-patch -k' output.
3434

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+
3540
-u::
3641
The commit log message, author name and author email are
3742
taken from the e-mail, and after minimally decoding MIME

builtin-mailinfo.c

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
static FILE *cmitmsg, *patchfile, *fin, *fout;
1111

1212
static int keep_subject;
13+
static int keep_non_patch_brackets_in_subject;
1314
static const char *metainfo_charset;
1415
static struct strbuf line = STRBUF_INIT;
1516
static struct strbuf name = STRBUF_INIT;
@@ -221,35 +222,41 @@ static int is_multipart_boundary(const struct strbuf *line)
221222

222223
static void cleanup_subject(struct strbuf *subject)
223224
{
224-
char *pos;
225-
size_t remove;
226-
while (subject->len) {
227-
switch (*subject->buf) {
225+
size_t at = 0;
226+
227+
while (at < subject->len) {
228+
char *pos;
229+
size_t remove;
230+
231+
switch (subject->buf[at]) {
228232
case 'r': case 'R':
229-
if (subject->len <= 3)
233+
if (subject->len <= at + 3)
230234
break;
231-
if (!memcmp(subject->buf + 1, "e:", 2)) {
232-
strbuf_remove(subject, 0, 3);
235+
if (!memcmp(subject->buf + at + 1, "e:", 2)) {
236+
strbuf_remove(subject, at, 3);
233237
continue;
234238
}
239+
at++;
235240
break;
236241
case ' ': case '\t': case ':':
237-
strbuf_remove(subject, 0, 1);
242+
strbuf_remove(subject, at, 1);
238243
continue;
239244
case '[':
240-
if ((pos = strchr(subject->buf, ']'))) {
241-
remove = pos - subject->buf;
242-
if (remove <= (subject->len - remove) * 2) {
243-
strbuf_remove(subject, 0, remove + 1);
244-
continue;
245-
}
246-
} else
247-
strbuf_remove(subject, 0, 1);
248-
break;
245+
pos = strchr(subject->buf + at, ']');
246+
if (!pos)
247+
break;
248+
remove = pos - subject->buf + at + 1;
249+
if (!keep_non_patch_brackets_in_subject ||
250+
(7 <= remove &&
251+
memmem(subject->buf + at, remove, "PATCH", 5)))
252+
strbuf_remove(subject, at, remove);
253+
else
254+
at += remove;
255+
continue;
249256
}
250-
strbuf_trim(subject);
251-
return;
257+
break;
252258
}
259+
strbuf_trim(subject);
253260
}
254261

255262
static void cleanup_space(struct strbuf *sb)
@@ -1014,7 +1021,7 @@ static int git_mailinfo_config(const char *var, const char *value, void *unused)
10141021
}
10151022

10161023
static const char mailinfo_usage[] =
1017-
"git mailinfo [-k] [-u | --encoding=<encoding> | -n] [--scissors | --no-scissors] msg patch < mail >info";
1024+
"git mailinfo [-k|-b] [-u | --encoding=<encoding> | -n] [--scissors | --no-scissors] msg patch < mail >info";
10181025

10191026
int cmd_mailinfo(int argc, const char **argv, const char *prefix)
10201027
{
@@ -1031,6 +1038,8 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
10311038
while (1 < argc && argv[1][0] == '-') {
10321039
if (!strcmp(argv[1], "-k"))
10331040
keep_subject = 1;
1041+
else if (!strcmp(argv[1], "-b"))
1042+
keep_non_patch_brackets_in_subject = 1;
10341043
else if (!strcmp(argv[1], "-u"))
10351044
metainfo_charset = def_charset;
10361045
else if (!strcmp(argv[1], "-n"))

0 commit comments

Comments
 (0)