Skip to content

Commit 09684a1

Browse files
committed
Merge branch 'dd/format-patch-rfc-updates'
"git format-patch --rfc --subject-prefix=<foo>" used to ignore the "--subject-prefix" option and used "[RFC PATCH]"; now we will add "RFC" prefix to whatever subject prefix is specified. This is a backward compatible change that may deserve a note. * dd/format-patch-rfc-updates: format-patch: --rfc honors what --subject-prefix sets
2 parents 32de857 + e0d7db7 commit 09684a1

File tree

3 files changed

+48
-23
lines changed

3 files changed

+48
-23
lines changed

Documentation/git-format-patch.txt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,15 @@ populated with placeholder text.
221221

222222
--subject-prefix=<subject prefix>::
223223
Instead of the standard '[PATCH]' prefix in the subject
224-
line, instead use '[<subject prefix>]'. This
225-
allows for useful naming of a patch series, and can be
226-
combined with the `--numbered` option.
224+
line, instead use '[<subject prefix>]'. This can be used
225+
to name a patch series, and can be combined with the
226+
`--numbered` option.
227+
+
228+
The configuration variable `format.subjectPrefix` may also be used
229+
to configure a subject prefix to apply to a given repository for
230+
all patches. This is often useful on mailing lists which receive
231+
patches for several repositories and can be used to disambiguate
232+
the patches (with a value of e.g. "PATCH my-project").
227233

228234
--filename-max-length=<n>::
229235
Instead of the standard 64 bytes, chomp the generated output
@@ -233,9 +239,9 @@ populated with placeholder text.
233239
variable, or 64 if unconfigured.
234240

235241
--rfc::
236-
Alias for `--subject-prefix="RFC PATCH"`. RFC means "Request For
237-
Comments"; use this when sending an experimental patch for
238-
discussion rather than application.
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.
239245

240246
-v <n>::
241247
--reroll-count=<n>::

builtin/log.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,19 +1480,16 @@ static int subject_prefix = 0;
14801480
static int subject_prefix_callback(const struct option *opt, const char *arg,
14811481
int unset)
14821482
{
1483+
struct strbuf *sprefix;
1484+
14831485
BUG_ON_OPT_NEG(unset);
1486+
sprefix = opt->value;
14841487
subject_prefix = 1;
1485-
((struct rev_info *)opt->value)->subject_prefix = arg;
1488+
strbuf_reset(sprefix);
1489+
strbuf_addstr(sprefix, arg);
14861490
return 0;
14871491
}
14881492

1489-
static int rfc_callback(const struct option *opt, const char *arg, int unset)
1490-
{
1491-
BUG_ON_OPT_NEG(unset);
1492-
BUG_ON_OPT_ARG(arg);
1493-
return subject_prefix_callback(opt, "RFC PATCH", unset);
1494-
}
1495-
14961493
static int numbered_cmdline_opt = 0;
14971494

14981495
static int numbered_callback(const struct option *opt, const char *arg,
@@ -1920,6 +1917,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
19201917
struct strbuf rdiff_title = STRBUF_INIT;
19211918
struct strbuf sprefix = STRBUF_INIT;
19221919
int creation_factor = -1;
1920+
int rfc = 0;
19231921

19241922
const struct option builtin_format_patch_options[] = {
19251923
OPT_CALLBACK_F('n', "numbered", &numbered, NULL,
@@ -1943,15 +1941,13 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
19431941
N_("mark the series as Nth re-roll")),
19441942
OPT_INTEGER(0, "filename-max-length", &fmt_patch_name_max,
19451943
N_("max length of output filename")),
1946-
OPT_CALLBACK_F(0, "rfc", &rev, NULL,
1947-
N_("use [RFC PATCH] instead of [PATCH]"),
1948-
PARSE_OPT_NOARG | PARSE_OPT_NONEG, rfc_callback),
1944+
OPT_BOOL(0, "rfc", &rfc, N_("use [RFC PATCH] instead of [PATCH]")),
19491945
OPT_STRING(0, "cover-from-description", &cover_from_description_arg,
19501946
N_("cover-from-description-mode"),
19511947
N_("generate parts of a cover letter based on a branch's description")),
19521948
OPT_FILENAME(0, "description-file", &description_file,
19531949
N_("use branch description from file")),
1954-
OPT_CALLBACK_F(0, "subject-prefix", &rev, N_("prefix"),
1950+
OPT_CALLBACK_F(0, "subject-prefix", &sprefix, N_("prefix"),
19551951
N_("use [<prefix>] instead of [PATCH]"),
19561952
PARSE_OPT_NONEG, subject_prefix_callback),
19571953
OPT_CALLBACK_F('o', "output-directory", &output_directory,
@@ -2031,11 +2027,11 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
20312027
rev.max_parents = 1;
20322028
rev.diffopt.flags.recursive = 1;
20332029
rev.diffopt.no_free = 1;
2034-
rev.subject_prefix = fmt_patch_subject_prefix;
20352030
memset(&s_r_opt, 0, sizeof(s_r_opt));
20362031
s_r_opt.def = "HEAD";
20372032
s_r_opt.revarg_opt = REVARG_COMMITTISH;
20382033

2034+
strbuf_addstr(&sprefix, fmt_patch_subject_prefix);
20392035
if (format_no_prefix)
20402036
diff_set_noprefix(&rev.diffopt);
20412037

@@ -2063,13 +2059,16 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
20632059
if (cover_from_description_arg)
20642060
cover_from_description_mode = parse_cover_from_description(cover_from_description_arg);
20652061

2062+
if (rfc)
2063+
strbuf_insertstr(&sprefix, 0, "RFC ");
2064+
20662065
if (reroll_count) {
2067-
strbuf_addf(&sprefix, "%s v%s",
2068-
rev.subject_prefix, reroll_count);
2066+
strbuf_addf(&sprefix, " v%s", reroll_count);
20692067
rev.reroll_count = reroll_count;
2070-
rev.subject_prefix = sprefix.buf;
20712068
}
20722069

2070+
rev.subject_prefix = sprefix.buf;
2071+
20732072
for (i = 0; i < extra_hdr.nr; i++) {
20742073
strbuf_addstr(&buf, extra_hdr.items[i].string);
20752074
strbuf_addch(&buf, '\n');

t/t4014-format-patch.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1373,7 +1373,27 @@ test_expect_success '--rfc' '
13731373
Subject: [RFC PATCH 1/1] header with . in it
13741374
EOF
13751375
git format-patch -n -1 --stdout --rfc >patch &&
1376-
grep ^Subject: patch >actual &&
1376+
grep "^Subject:" patch >actual &&
1377+
test_cmp expect actual
1378+
'
1379+
1380+
test_expect_success '--rfc does not overwrite prefix' '
1381+
cat >expect <<-\EOF &&
1382+
Subject: [RFC PATCH foobar 1/1] header with . in it
1383+
EOF
1384+
git -c format.subjectPrefix="PATCH foobar" \
1385+
format-patch -n -1 --stdout --rfc >patch &&
1386+
grep "^Subject:" patch >actual &&
1387+
test_cmp expect actual
1388+
'
1389+
1390+
test_expect_success '--rfc is argument order independent' '
1391+
cat >expect <<-\EOF &&
1392+
Subject: [RFC PATCH foobar 1/1] header with . in it
1393+
EOF
1394+
git format-patch -n -1 --stdout --rfc \
1395+
--subject-prefix="PATCH foobar" >patch &&
1396+
grep "^Subject:" patch >actual &&
13771397
test_cmp expect actual
13781398
'
13791399

0 commit comments

Comments
 (0)