Skip to content

Commit 2d9e4a4

Browse files
robbat2Junio C Hamano
authored andcommitted
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>
1 parent 566f5b2 commit 2d9e4a4

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

Documentation/git-format-patch.txt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ SYNOPSIS
1010
--------
1111
[verse]
1212
'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>]
1819

1920
DESCRIPTION
2021
-----------
@@ -98,6 +99,12 @@ include::diff-options.txt[]
9899
patches being generated, and any patch that matches is
99100
ignored.
100101

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+
101108
--suffix=.<sfx>::
102109
Instead of using `.patch` as the suffix for generated
103110
filenames, use specifed suffix. A common alternative is

builtin-log.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
417417
int numbered = 0;
418418
int start_number = -1;
419419
int keep_subject = 0;
420+
int subject_prefix = 0;
420421
int ignore_if_in_upstream = 0;
421422
int thread = 0;
422423
const char *in_reply_to = NULL;
@@ -434,6 +435,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
434435
rev.ignore_merges = 1;
435436
rev.diffopt.msg_sep = "";
436437
rev.diffopt.recursive = 1;
438+
rev.subject_prefix = "PATCH";
437439

438440
rev.extra_headers = extra_headers;
439441

@@ -509,8 +511,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
509511
if (i == argc)
510512
die("Need a Message-Id for --in-reply-to");
511513
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="))
514518
fmt_patch_suffix = argv[i] + 9;
515519
else
516520
argv[j++] = argv[i];
@@ -521,6 +525,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
521525
start_number = 1;
522526
if (numbered && keep_subject)
523527
die ("-n and -k are mutually exclusive.");
528+
if (keep_subject && subject_prefix)
529+
die ("--subject-prefix and -k are mutually exclusive.");
524530

525531
argc = setup_revisions(argc, argv, &rev, "HEAD");
526532
if (argc > 1)

log-tree.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,20 @@ void show_log(struct rev_info *opt, const char *sep)
165165
if (opt->total > 0) {
166166
static char buffer[64];
167167
snprintf(buffer, sizeof(buffer),
168-
"Subject: [PATCH %0*d/%d] ",
168+
"Subject: [%s %0*d/%d] ",
169+
opt->subject_prefix,
169170
digits_in_number(opt->total),
170171
opt->nr, opt->total);
171172
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 {
175180
subject = "Subject: ";
181+
}
176182

177183
printf("From %s Mon Sep 17 00:00:00 2001\n", sha1);
178184
if (opt->message_id)

revision.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ struct rev_info {
7878
const char *add_signoff;
7979
const char *extra_headers;
8080
const char *log_reencode;
81+
const char *subject_prefix;
8182
int no_inline;
8283

8384
/* Filter by commit log message */

0 commit comments

Comments
 (0)