Skip to content

Commit ce48fb2

Browse files
committed
format-patch: allow --rfc to optionally take a value, like --rfc=WIP
With the "--rfc" option, we can tweak the "[PATCH]" (or whatever string specified with the "--subject-prefix" option, instead of "PATCH") that we prefix the title of the commit with into "[RFC PATCH]", but some projects may want "[rfc PATCH]". Adding a new option, e.g., "--rfc-lowercase", to support such need every time somebody wants to use different strings would lead to insanity of accumulating unbounded number of such options. Allow an optional value specified for the option, so that users can use "--rfc=rfc" (think of "--rfc" without value as a short-hand for "--rfc=RFC") if they wanted to. This can of course be (ab)used to make the prefix "[WIP PATCH]" by passing "--rfc=WIP". Passing an empty string, i.e., "--rfc=", is the same as "--no-rfc" to override an option given earlier on the same command line. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 21306a0 commit ce48fb2

File tree

3 files changed

+48
-11
lines changed

3 files changed

+48
-11
lines changed

Documentation/git-format-patch.txt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ SYNOPSIS
2020
[--in-reply-to=<message-id>] [--suffix=.<sfx>]
2121
[--ignore-if-in-upstream] [--always]
2222
[--cover-from-description=<mode>]
23-
[--rfc] [--subject-prefix=<subject-prefix>]
23+
[--rfc[=<rfc>]] [--subject-prefix=<subject-prefix>]
2424
[(--reroll-count|-v) <n>]
2525
[--to=<email>] [--cc=<email>]
2626
[--[no-]cover-letter] [--quiet]
@@ -238,10 +238,15 @@ the patches (with a value of e.g. "PATCH my-project").
238238
value of the `format.filenameMaxLength` configuration
239239
variable, or 64 if unconfigured.
240240

241-
--rfc::
242-
Prepends "RFC" to the subject prefix (producing "RFC PATCH" by
243-
default). RFC means "Request For Comments"; use this when sending
244-
an experimental patch for discussion rather than application.
241+
--rfc[=<rfc>]::
242+
Prepends the string _<rfc>_ (defaults to "RFC") to
243+
the subject prefix. As the subject prefix defaults to
244+
"PATCH", you'll get "RFC PATCH" by default.
245+
+
246+
RFC means "Request For Comments"; use this when sending
247+
an experimental patch for discussion rather than application.
248+
"--rfc=WIP" may also be a useful way to indicate that a patch
249+
is not complete yet ("WIP" stands for "Work In Progress").
245250

246251
-v <n>::
247252
--reroll-count=<n>::

builtin/log.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,6 +1494,19 @@ static int subject_prefix_callback(const struct option *opt, const char *arg,
14941494
return 0;
14951495
}
14961496

1497+
static int rfc_callback(const struct option *opt, const char *arg,
1498+
int unset)
1499+
{
1500+
const char **rfc = opt->value;
1501+
1502+
*rfc = opt->value;
1503+
if (unset)
1504+
*rfc = NULL;
1505+
else
1506+
*rfc = arg ? arg : "RFC";
1507+
return 0;
1508+
}
1509+
14971510
static int numbered_cmdline_opt = 0;
14981511

14991512
static int numbered_callback(const struct option *opt, const char *arg,
@@ -1907,8 +1920,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
19071920
struct strbuf rdiff2 = STRBUF_INIT;
19081921
struct strbuf rdiff_title = STRBUF_INIT;
19091922
struct strbuf sprefix = STRBUF_INIT;
1923+
const char *rfc = NULL;
19101924
int creation_factor = -1;
1911-
int rfc = 0;
19121925

19131926
const struct option builtin_format_patch_options[] = {
19141927
OPT_CALLBACK_F('n', "numbered", &numbered, NULL,
@@ -1932,7 +1945,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
19321945
N_("mark the series as Nth re-roll")),
19331946
OPT_INTEGER(0, "filename-max-length", &fmt_patch_name_max,
19341947
N_("max length of output filename")),
1935-
OPT_BOOL(0, "rfc", &rfc, N_("use [RFC PATCH] instead of [PATCH]")),
1948+
OPT_CALLBACK_F(0, "rfc", &rfc, N_("rfc"),
1949+
N_("add <rfc> (default 'RFC') before 'PATCH'"),
1950+
PARSE_OPT_OPTARG, rfc_callback),
19361951
OPT_STRING(0, "cover-from-description", &cover_from_description_arg,
19371952
N_("cover-from-description-mode"),
19381953
N_("generate parts of a cover letter based on a branch's description")),
@@ -2050,8 +2065,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
20502065
if (cover_from_description_arg)
20512066
cover_from_description_mode = parse_cover_from_description(cover_from_description_arg);
20522067

2053-
if (rfc)
2054-
strbuf_insertstr(&sprefix, 0, "RFC ");
2068+
if (rfc && rfc[0])
2069+
strbuf_insertf(&sprefix, 0, "%s ", rfc);
20552070

20562071
if (reroll_count) {
20572072
strbuf_addf(&sprefix, " v%s", reroll_count);

t/t4014-format-patch.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,13 +1368,30 @@ test_expect_success 'empty subject prefix does not have extra space' '
13681368
test_cmp expect actual
13691369
'
13701370

1371-
test_expect_success '--rfc' '
1371+
test_expect_success '--rfc and --no-rfc' '
13721372
cat >expect <<-\EOF &&
13731373
Subject: [RFC PATCH 1/1] header with . in it
13741374
EOF
13751375
git format-patch -n -1 --stdout --rfc >patch &&
13761376
grep "^Subject:" patch >actual &&
1377-
test_cmp expect actual
1377+
test_cmp expect actual &&
1378+
git format-patch -n -1 --stdout --rfc --no-rfc >patch &&
1379+
sed -e "s/RFC //" expect >expect-raw &&
1380+
grep "^Subject:" patch >actual &&
1381+
test_cmp expect-raw actual
1382+
'
1383+
1384+
test_expect_success '--rfc=WIP and --rfc=' '
1385+
cat >expect <<-\EOF &&
1386+
Subject: [WIP PATCH 1/1] header with . in it
1387+
EOF
1388+
git format-patch -n -1 --stdout --rfc=WIP >patch &&
1389+
grep "^Subject:" patch >actual &&
1390+
test_cmp expect actual &&
1391+
git format-patch -n -1 --stdout --rfc --rfc= >patch &&
1392+
sed -e "s/WIP //" expect >expect-raw &&
1393+
grep "^Subject:" patch >actual &&
1394+
test_cmp expect-raw actual
13781395
'
13791396

13801397
test_expect_success '--rfc does not overwrite prefix' '

0 commit comments

Comments
 (0)