aboutsummaryrefslogtreecommitdiff
path: root/builtin-mailinfo.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2009-07-15 15:31:12 -0700
committerJunio C Hamano <gitster@pobox.com>2009-07-29 12:34:56 -0700
commit17635fc900674037bcaa9ca0fadcc5c23d6162e9 (patch)
treea6a510c95f10058f0a148abee68563736ac67ba6 /builtin-mailinfo.c
parent0a53e9ddeaddad63ad106860237bbf53411d11a7 (diff)
downloadgit-17635fc900674037bcaa9ca0fadcc5c23d6162e9.tar.gz
git-17635fc900674037bcaa9ca0fadcc5c23d6162e9.tar.xz
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>
Diffstat (limited to 'builtin-mailinfo.c')
-rw-r--r--builtin-mailinfo.c49
1 files changed, 29 insertions, 20 deletions
diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
index 92637ac0b..a5949e2c9 100644
--- a/builtin-mailinfo.c
+++ b/builtin-mailinfo.c
@@ -10,6 +10,7 @@
static FILE *cmitmsg, *patchfile, *fin, *fout;
static int keep_subject;
+static int keep_non_patch_brackets_in_subject;
static const char *metainfo_charset;
static struct strbuf line = STRBUF_INIT;
static struct strbuf name = STRBUF_INIT;
@@ -219,35 +220,41 @@ static int is_multipart_boundary(const struct strbuf *line)
static void cleanup_subject(struct strbuf *subject)
{
- char *pos;
- size_t remove;
- while (subject->len) {
- switch (*subject->buf) {
+ size_t at = 0;
+
+ while (at < subject->len) {
+ char *pos;
+ size_t remove;
+
+ switch (subject->buf[at]) {
case 'r': case 'R':
- if (subject->len <= 3)
+ if (subject->len <= at + 3)
break;
- if (!memcmp(subject->buf + 1, "e:", 2)) {
- strbuf_remove(subject, 0, 3);
+ if (!memcmp(subject->buf + at + 1, "e:", 2)) {
+ strbuf_remove(subject, at, 3);
continue;
}
+ at++;
break;
case ' ': case '\t': case ':':
- strbuf_remove(subject, 0, 1);
+ strbuf_remove(subject, at, 1);
continue;
case '[':
- if ((pos = strchr(subject->buf, ']'))) {
- remove = pos - subject->buf;
- if (remove <= (subject->len - remove) * 2) {
- strbuf_remove(subject, 0, remove + 1);
- continue;
- }
- } else
- strbuf_remove(subject, 0, 1);
- break;
+ pos = strchr(subject->buf + at, ']');
+ if (!pos)
+ break;
+ 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;
}
- strbuf_trim(subject);
- return;
+ break;
}
+ strbuf_trim(subject);
}
static void cleanup_space(struct strbuf *sb)
@@ -931,7 +938,7 @@ static int mailinfo(FILE *in, FILE *out, int ks, const char *encoding,
}
static const char mailinfo_usage[] =
- "git mailinfo [-k] [-u | --encoding=<encoding> | -n] msg patch <mail >info";
+ "git mailinfo [-k|-b] [-u | --encoding=<encoding> | -n] msg patch <mail >info";
int cmd_mailinfo(int argc, const char **argv, const char *prefix)
{
@@ -948,6 +955,8 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
while (1 < argc && argv[1][0] == '-') {
if (!strcmp(argv[1], "-k"))
keep_subject = 1;
+ else if (!strcmp(argv[1], "-b"))
+ keep_non_patch_brackets_in_subject = 1;
else if (!strcmp(argv[1], "-u"))
metainfo_charset = def_charset;
else if (!strcmp(argv[1], "-n"))