From: Drew DeVault <sir@cmpwn.com>
To: git@vger.kernel.org
Cc: Drew DeVault <sir@cmpwn.com>
Subject: [PATCH] builtin/log.c: prepend "RFC" on --rfc
Date: Mon, 28 Aug 2023 14:50:34 +0200 [thread overview]
Message-ID: <20230828125132.25144-1-sir@cmpwn.com> (raw)
Rather than replacing the configured subject prefix (either through the
git config or command line) entirely with "RFC PATCH", this change
prepends RFC to whatever subject prefix was already in use.
This is useful, for example, when a user is working on a repository that
has a subject prefix considered to disambiguate patches:
git config format.subjectPrefix 'PATCH my-project'
Prior to this change, formatting patches with --rfc would lose the
'my-project' information.
Signed-off-by: Drew DeVault <sir@cmpwn.com>
---
Implementation note: this introduces a small memory leak, but freeing it
requires a non-trivial amount of refactoring and some dubious choices
that I was not sure of for a small patch; and it seems like memory leaks
in this context are tolerated anyway from a perusal of the existing
code.
Documentation/git-format-patch.txt | 6 +++---
builtin/log.c | 15 ++++++++++++++-
t/t4014-format-patch.sh | 9 +++++++++
3 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt
index 373b46fc0d..fdc52cf826 100644
--- a/Documentation/git-format-patch.txt
+++ b/Documentation/git-format-patch.txt
@@ -229,9 +229,9 @@ populated with placeholder text.
variable, or 64 if unconfigured.
--rfc::
- Alias for `--subject-prefix="RFC PATCH"`. RFC means "Request For
- Comments"; use this when sending an experimental patch for
- discussion rather than application.
+ Prepends "RFC" to the subject prefix (producing "RFC PATCH" by
+ default). RFC means "Request For Comments"; use this when sending
+ an experimental patch for discussion rather than application.
-v <n>::
--reroll-count=<n>::
diff --git a/builtin/log.c b/builtin/log.c
index db3a88bfe9..d986faebed 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1476,9 +1476,22 @@ static int subject_prefix_callback(const struct option *opt, const char *arg,
static int rfc_callback(const struct option *opt, const char *arg, int unset)
{
+ int n;
+ char *prefix;
+ const char *prev;
+
BUG_ON_OPT_NEG(unset);
BUG_ON_OPT_ARG(arg);
- return subject_prefix_callback(opt, "RFC PATCH", unset);
+
+ prev = ((struct rev_info *)opt->value)->subject_prefix;
+ assert(prev != NULL);
+ n = snprintf(NULL, 0, "RFC %s", prev);
+ assert(n > 0);
+ prefix = xmalloc(n + 1);
+ n = snprintf(prefix, n + 1, "RFC %s", prev);
+ assert(n > 0);
+
+ return subject_prefix_callback(opt, prefix, unset);
}
static int numbered_cmdline_opt = 0;
diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
index 3cf2b7a7fb..a7fe839683 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -1377,6 +1377,15 @@ test_expect_success '--rfc' '
test_cmp expect actual
'
+test_expect_success '--rfc does not overwrite prefix' '
+ cat >expect <<-\EOF &&
+ Subject: [RFC PATCH foobar 1/1] header with . in it
+ EOF
+ git format-patch -n -1 --stdout --subject-prefix "PATCH foobar" --rfc >patch &&
+ grep ^Subject: patch >actual &&
+ test_cmp expect actual
+'
+
test_expect_success '--from=ident notices bogus ident' '
test_must_fail git format-patch -1 --stdout --from=foo >patch
'
--
2.42.0
next reply other threads:[~2023-08-28 12:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-28 12:50 Drew DeVault [this message]
2023-08-28 14:42 ` [PATCH] builtin/log.c: prepend "RFC" on --rfc Jeff King
2023-08-28 14:49 ` Drew DeVault
2023-08-28 16:30 ` Phillip Wood
2023-08-28 17:42 ` Jeff King
2023-08-28 18:12 ` Junio C Hamano
2023-08-28 15:31 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230828125132.25144-1-sir@cmpwn.com \
--to=sir@cmpwn.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).