Merge branch 'jc/mailinfo-remove-brackets'

Conflicts:
	Documentation/git-mailinfo.txt
	builtin-mailinfo.c
This commit is contained in:
Junio C Hamano 2009-11-30 14:43:24 -08:00
commit d268cb940d
2 changed files with 35 additions and 21 deletions

View File

@ -8,7 +8,7 @@ git-mailinfo - Extracts patch and authorship from a single e-mail message
SYNOPSIS SYNOPSIS
-------- --------
'git mailinfo' [-k] [-u | --encoding=<encoding> | -n] [--scissors] <msg> <patch> 'git mailinfo' [-k|-b] [-u | --encoding=<encoding> | -n] [--scissors] <msg> <patch>
DESCRIPTION DESCRIPTION
@ -32,6 +32,11 @@ OPTIONS
munging, and is most useful when used to read back munging, and is most useful when used to read back
'git-format-patch -k' output. 'git-format-patch -k' output.
-b::
When -k is not in effect, all leading strings bracketed with '['
and ']' pairs are stripped. This option limits the stripping to
only the pairs whose bracketed string contains the word "PATCH".
-u:: -u::
The commit log message, author name and author email are The commit log message, author name and author email are
taken from the e-mail, and after minimally decoding MIME taken from the e-mail, and after minimally decoding MIME

View File

@ -10,6 +10,7 @@
static FILE *cmitmsg, *patchfile, *fin, *fout; static FILE *cmitmsg, *patchfile, *fin, *fout;
static int keep_subject; static int keep_subject;
static int keep_non_patch_brackets_in_subject;
static const char *metainfo_charset; static const char *metainfo_charset;
static struct strbuf line = STRBUF_INIT; static struct strbuf line = STRBUF_INIT;
static struct strbuf name = STRBUF_INIT; static struct strbuf name = STRBUF_INIT;
@ -221,35 +222,41 @@ static int is_multipart_boundary(const struct strbuf *line)
static void cleanup_subject(struct strbuf *subject) static void cleanup_subject(struct strbuf *subject)
{ {
size_t at = 0;
while (at < subject->len) {
char *pos; char *pos;
size_t remove; size_t remove;
while (subject->len) {
switch (*subject->buf) { switch (subject->buf[at]) {
case 'r': case 'R': case 'r': case 'R':
if (subject->len <= 3) if (subject->len <= at + 3)
break; break;
if (!memcmp(subject->buf + 1, "e:", 2)) { if (!memcmp(subject->buf + at + 1, "e:", 2)) {
strbuf_remove(subject, 0, 3); strbuf_remove(subject, at, 3);
continue; continue;
} }
at++;
break; break;
case ' ': case '\t': case ':': case ' ': case '\t': case ':':
strbuf_remove(subject, 0, 1); strbuf_remove(subject, at, 1);
continue; continue;
case '[': case '[':
if ((pos = strchr(subject->buf, ']'))) { pos = strchr(subject->buf + at, ']');
remove = pos - subject->buf; if (!pos)
if (remove <= (subject->len - remove) * 2) { break;
strbuf_remove(subject, 0, remove + 1); remove = pos - subject->buf + at + 1;
if (!keep_non_patch_brackets_in_subject ||
(7 <= remove &&
memmem(subject->buf + at, remove, "PATCH", 5)))
strbuf_remove(subject, at, remove);
else
at += remove;
continue; continue;
} }
} else
strbuf_remove(subject, 0, 1);
break; break;
} }
strbuf_trim(subject); strbuf_trim(subject);
return;
}
} }
static void cleanup_space(struct strbuf *sb) static void cleanup_space(struct strbuf *sb)
@ -1014,7 +1021,7 @@ static int git_mailinfo_config(const char *var, const char *value, void *unused)
} }
static const char mailinfo_usage[] = static const char mailinfo_usage[] =
"git mailinfo [-k] [-u | --encoding=<encoding> | -n] [--scissors | --no-scissors] msg patch < mail >info"; "git mailinfo [-k|-b] [-u | --encoding=<encoding> | -n] [--scissors | --no-scissors] msg patch < mail >info";
int cmd_mailinfo(int argc, const char **argv, const char *prefix) int cmd_mailinfo(int argc, const char **argv, const char *prefix)
{ {
@ -1031,6 +1038,8 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
while (1 < argc && argv[1][0] == '-') { while (1 < argc && argv[1][0] == '-') {
if (!strcmp(argv[1], "-k")) if (!strcmp(argv[1], "-k"))
keep_subject = 1; keep_subject = 1;
else if (!strcmp(argv[1], "-b"))
keep_non_patch_brackets_in_subject = 1;
else if (!strcmp(argv[1], "-u")) else if (!strcmp(argv[1], "-u"))
metainfo_charset = def_charset; metainfo_charset = def_charset;
else if (!strcmp(argv[1], "-n")) else if (!strcmp(argv[1], "-n"))