diff mbox series

[GSoC,RFC,5/6] log-tree: add subject prefix in output email subject

Message ID 20250303220029.10716-6-lucasseikioshiro@gmail.com (mailing list archive)
State New
Headers show
Series Add --subject-extra-prefix flag to format-patch | expand

Commit Message

Lucas Seiki Oshiro March 3, 2025, 10 p.m. UTC
When an extra subject prefix is provided by the user when calling
`format-patch --subject-extra-prefix`, insert it between brackets at the
beginning of the the patch subject. Don't change the behavior when this
flag is not used.

For example, this `format-patch` call:

`git format-patch -1 --subject-extra-prefix EXTRA -n -v2`

will create a patch with the subject beginning with:

`Subject: [EXTRA][PATCH v2 1/1]`

Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
---
 log-tree.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/log-tree.c b/log-tree.c
index 8b184d6776..d72ab25585 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -478,17 +478,21 @@  void fmt_output_commit(struct strbuf *filename,
 
 void fmt_output_email_subject(struct strbuf *sb, struct rev_info *opt)
 {
+	strbuf_addstr(sb, "Subject: ");
+
+	if (opt->subject_extra_prefix && *opt->subject_extra_prefix)
+		strbuf_addf(sb, "[%s]",
+			    opt->subject_extra_prefix);
+
 	if (opt->total > 0) {
-		strbuf_addf(sb, "Subject: [%s%s%0*d/%d] ",
+		strbuf_addf(sb, "[%s%s%0*d/%d] ",
 			    opt->subject_prefix,
 			    *opt->subject_prefix ? " " : "",
 			    decimal_width(opt->total),
 			    opt->nr, opt->total);
 	} else if (opt->total == 0 && opt->subject_prefix && *opt->subject_prefix) {
-		strbuf_addf(sb, "Subject: [%s] ",
+		strbuf_addf(sb, "[%s] ",
 			    opt->subject_prefix);
-	} else {
-		strbuf_addstr(sb, "Subject: ");
 	}
 }