Skip to content

Commit 708e925

Browse files
committed
Merge branch 'jc/format-patch-rfc-more'
The "--rfc" option of "git format-patch" learned to take an optional string value to be used in place of "RFC" to tweak the "[PATCH]" on the subject header. * jc/format-patch-rfc-more: format-patch: "--rfc=-(WIP)" appends to produce [PATCH (WIP)] format-patch: allow --rfc to optionally take a value, like --rfc=WIP
2 parents 07fc827 + ce36894 commit 708e925

File tree

3 files changed

+65
-10
lines changed

3 files changed

+65
-10
lines changed

Documentation/git-format-patch.txt

Lines changed: 16 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,21 @@ 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").
250+
+
251+
If the convention of the receiving community for a particular extra
252+
string is to have it _after_ the subject prefix, the string _<rfc>_
253+
can be prefixed with a dash ("`-`") to signal that the the rest of
254+
the _<rfc>_ string should be appended to the subject prefix instead,
255+
e.g., `--rfc='-(WIP)'` results in "PATCH (WIP)".
245256

246257
-v <n>::
247258
--reroll-count=<n>::

builtin/log.c

Lines changed: 22 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,9 +2065,12 @@ 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]) {
20552069
subject_prefix = 1;
2070+
if (rfc[0] == '-')
2071+
strbuf_addf(&sprefix, " %s", rfc + 1);
2072+
else
2073+
strbuf_insertf(&sprefix, 0, "%s ", rfc);
20562074
}
20572075

20582076
if (reroll_count) {

t/t4014-format-patch.sh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1368,12 +1368,38 @@ 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 &&
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
1395+
'
1396+
1397+
test_expect_success '--rfc=-(WIP) appends' '
1398+
cat >expect <<-\EOF &&
1399+
Subject: [PATCH (WIP) 1/1] header with . in it
1400+
EOF
1401+
git format-patch -n -1 --stdout --rfc="-(WIP)" >patch &&
1402+
grep "^Subject:" patch >actual &&
13771403
test_cmp expect actual
13781404
'
13791405

0 commit comments

Comments
 (0)