format-patch: "--rfc=-(WIP)" appends to produce [PATCH (WIP)]

In the previous step, the "--rfc" option of "format-patch" learned to take an optional string value to prepend to the subject prefix, so that --rfc=WIP can give "[WIP PATCH]". There may be cases in which the extra string wants to come after the subject prefix. Extend the mechanism to allow "--rfc=-(WIP)" [*] to signal that the extra string is to be appended instead of getting prepended, resulting in "[PATCH (WIP)]". In the documentation, discourage (ab)using "--rfc=-RFC" to say "[PATCH RFC]" just to be different, when "[RFC PATCH]" is the norm. [Footnote] * The syntax takes inspiration from Perl's open syntax that opens pipes "open fh, '|-', 'cmd'", where the dash signals "the other stuff comes here". Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Apr 23, 2024 at 10:52 UTC ce36894509bac4c03fd524fc668b1e43d6e56ee1
3 files changed +21 -2
Documentation/git-format-patch.txt
+6
@@ -247,6 +247,12 @@ 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)".
256
257 -v <n>::
258 --reroll-count=<n>::
builtin/log.c
+6 -2
@@ -2065,8 +2065,12 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
2065 if (cover_from_description_arg)
2066 cover_from_description_mode = parse_cover_from_description(cover_from_description_arg);
2067
2068 - if (rfc && rfc[0])
2069 - strbuf_insertf(&sprefix, 0, "%s ", rfc);
2068 + if (rfc && rfc[0]) {
2069 + if (rfc[0] == '-')
2070 + strbuf_addf(&sprefix, " %s", rfc + 1);
2071 + else
2072 + strbuf_insertf(&sprefix, 0, "%s ", rfc);
2073 + }
2074
2075 if (reroll_count) {
2076 strbuf_addf(&sprefix, " v%s", reroll_count);
t/t4014-format-patch.sh
+9
@@ -1394,6 +1394,15 @@ test_expect_success '--rfc=WIP and --rfc=' '
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 &&
1403 + test_cmp expect actual
1404 +'
1405 +
1406 test_expect_success '--rfc does not overwrite prefix' '
1407 cat >expect <<-\EOF &&
1408 Subject: [RFC PATCH foobar 1/1] header with . in it