@matheusbsbs / matheus-bagliano / commits / 2d9e4a47d1
Fork 0

Add custom subject prefix support to format-patch (take 3)

Add a new option to git-format-patch, entitled --subject-prefix that allows control of the subject prefix '[PATCH]'. Using this option, the text 'PATCH' is replaced with whatever input is provided to the option. This allows easily generating patches like '[PATCH 2.6.21-rc3]' or properly numbered series like '[-mm3 PATCH N/M]'. This patch provides the implementation and documentation. Signed-off-by: Robin H. Johnson <robbat2@gentoo.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Robin H. Johnson committed Apr 11, 2007 at 16:58 UTC 2d9e4a47d16e9d2100cc88ef6126aa7619be51ed
4 files changed +31 -11
Documentation/git-format-patch.txt
+12 -5
@@ -10,11 +10,12 @@ SYNOPSIS
10 --------
11 [verse]
12 'git-format-patch' [-n | -k] [-o <dir> | --stdout] [--thread]
13 - [--attach[=<boundary>] | --inline[=<boundary>]]
14 - [-s | --signoff] [<common diff options>] [--start-number <n>]
15 - [--in-reply-to=Message-Id] [--suffix=.<sfx>]
16 - [--ignore-if-in-upstream]
17 - <since>[..<until>]
13 + [--attach[=<boundary>] | --inline[=<boundary>]]
14 + [-s | --signoff] [<common diff options>] [--start-number <n>]
15 + [--in-reply-to=Message-Id] [--suffix=.<sfx>]
16 + [--ignore-if-in-upstream]
17 + [--subject-prefix=Subject-Prefix]
18 + <since>[..<until>]
19
20 DESCRIPTION
21 -----------
@@ -98,6 +99,12 @@ include::diff-options.txt[]
99 patches being generated, and any patch that matches is
100 ignored.
101
102 +--subject-prefix=<Subject-Prefix>::
103 + Instead of the standard '[PATCH]' prefix in the subject
104 + line, instead use '[<Subject-Prefix>]'. This
105 + allows for useful naming of a patch series, and can be
106 + combined with the --numbered option.
107 +
108 --suffix=.<sfx>::
109 Instead of using `.patch` as the suffix for generated
110 filenames, use specifed suffix. A common alternative is
builtin-log.c
+8 -2
@@ -417,6 +417,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
417 int numbered = 0;
418 int start_number = -1;
419 int keep_subject = 0;
420 + int subject_prefix = 0;
421 int ignore_if_in_upstream = 0;
422 int thread = 0;
423 const char *in_reply_to = NULL;
@@ -434,6 +435,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
435 rev.ignore_merges = 1;
436 rev.diffopt.msg_sep = "";
437 rev.diffopt.recursive = 1;
438 + rev.subject_prefix = "PATCH";
439
440 rev.extra_headers = extra_headers;
441
@@ -509,8 +511,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
511 if (i == argc)
512 die("Need a Message-Id for --in-reply-to");
513 in_reply_to = argv[i];
512 - }
513 - else if (!prefixcmp(argv[i], "--suffix="))
514 + } else if (!prefixcmp(argv[i], "--subject-prefix=")) {
515 + subject_prefix = 1;
516 + rev.subject_prefix = argv[i] + 17;
517 + } else if (!prefixcmp(argv[i], "--suffix="))
518 fmt_patch_suffix = argv[i] + 9;
519 else
520 argv[j++] = argv[i];
@@ -521,6 +525,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
525 start_number = 1;
526 if (numbered && keep_subject)
527 die ("-n and -k are mutually exclusive.");
528 + if (keep_subject && subject_prefix)
529 + die ("--subject-prefix and -k are mutually exclusive.");
530
531 argc = setup_revisions(argc, argv, &rev, "HEAD");
532 if (argc > 1)
log-tree.c
+10 -4
@@ -165,14 +165,20 @@ void show_log(struct rev_info *opt, const char *sep)
165 if (opt->total > 0) {
166 static char buffer[64];
167 snprintf(buffer, sizeof(buffer),
168 - "Subject: [PATCH %0*d/%d] ",
168 + "Subject: [%s %0*d/%d] ",
169 + opt->subject_prefix,
170 digits_in_number(opt->total),
171 opt->nr, opt->total);
172 subject = buffer;
172 - } else if (opt->total == 0)
173 - subject = "Subject: [PATCH] ";
174 - else
173 + } else if (opt->total == 0) {
174 + static char buffer[256];
175 + snprintf(buffer, sizeof(buffer),
176 + "Subject: [%s] ",
177 + opt->subject_prefix);
178 + subject = buffer;
179 + } else {
180 subject = "Subject: ";
181 + }
182
183 printf("From %s Mon Sep 17 00:00:00 2001\n", sha1);
184 if (opt->message_id)
revision.h
+1
@@ -78,6 +78,7 @@ struct rev_info {
78 const char *add_signoff;
79 const char *extra_headers;
80 const char *log_reencode;
81 + const char *subject_prefix;
82 int no_inline;
83
84 /* Filter by commit log message */