Skip to contentSkip to conversation

git-format-patch --subject-prefix support.

PATCH New Robin H. Johnson 3 participants 7 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

Add a new option to git-format-patch, entitled --subject-prefix that allows control of the subject prefix '[PATCH]'. Using this option, the text 'PATCH' is replaced with whatever input is provided to the option. This allows easily generating patches like '[PATCH 2.6.21-rc3]' or properly numbered series like '[-mm3 PATCH N/M]'.

1/2 - Implementation and documentation
2/2 - Test case

#1 lore raw

PATCH 1/2 Add custom subject prefix support to format-patch (take 3)

From: Robin H. Johnson <[email protected]>

Add a new option to git-format-patch, entitled --subject-prefix that allows control of the subject prefix '[PATCH]'. Using this option, the text 'PATCH' is replaced with whatever input is provided to the option. This allows easily generating patches like '[PATCH 2.6.21-rc3]' or properly numbered series like '[-mm3 PATCH N/M]'. This patch provides the implementation and documentation.

---
 Documentation/git-format-patch.txt |   17 ++++++++++++-----
 builtin-log.c                      |   10 ++++++++--
 log-tree.c                         |   14 ++++++++++----
 revision.h                         |    1 +
 4 files changed, 31 insertions(+), 11 deletions(-)
Documentation/git-format-patch.txt +12 -5
index 111d7c6..9965745 100644
@@ -10,11 +10,12 @@ SYNOPSIS
 --------
 [verse]
 'git-format-patch' [-n | -k] [-o <dir> | --stdout] [--thread]
-	           [--attach[=<boundary>] | --inline[=<boundary>]]
-	           [-s | --signoff] [<common diff options>] [--start-number <n>]
-		   [--in-reply-to=Message-Id] [--suffix=.<sfx>]
-		   [--ignore-if-in-upstream]
-		   <since>[..<until>]
+                 [--attach[=<boundary>] | --inline[=<boundary>]]
+                 [-s | --signoff] [<common diff options>]
+                 [--start-number <n>] [--in-reply-to=Message-Id]
+                 [--suffix=.<sfx>] [--ignore-if-in-upstream]
+                 [--subject-prefix=Subject-Prefix]
+                 <since>[..<until>]
 
 DESCRIPTION
 -----------
@@ -98,6 +99,12 @@ include::diff-options.txt[]
 	patches being generated, and any patch that matches is
 	ignored.
 
+--subject-prefix=<Subject-Prefix>::
+	Instead of the standard '[PATCH]' prefix in the subject
+	line, instead use '[<Subject-Prefix>]'. This
+	allows for useful naming of a patch series, and can be
+	combined with the --numbered option.
+
 --suffix=.<sfx>::
 	Instead of using `.patch` as the suffix for generated
 	filenames, use specifed suffix.  A common alternative is
builtin-log.c +8 -2
index 71df957..4a4890a 100644
@@ -417,6 +417,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 	int numbered = 0;
 	int start_number = -1;
 	int keep_subject = 0;
+	int subject_prefix = 0;
 	int ignore_if_in_upstream = 0;
 	int thread = 0;
 	const char *in_reply_to = NULL;
@@ -434,6 +435,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 	rev.ignore_merges = 1;
 	rev.diffopt.msg_sep = "";
 	rev.diffopt.recursive = 1;
+	rev.subject_prefix = "PATCH";
 
 	rev.extra_headers = extra_headers;
 
@@ -509,8 +511,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 			if (i == argc)
 				die("Need a Message-Id for --in-reply-to");
 			in_reply_to = argv[i];
-		}
-		else if (!prefixcmp(argv[i], "--suffix="))
+		} else if (!prefixcmp(argv[i], "--subject-prefix=")) {
+			subject_prefix = 1;
+			rev.subject_prefix = argv[i] + 17;
+		} else if (!prefixcmp(argv[i], "--suffix="))
 			fmt_patch_suffix = argv[i] + 9;
 		else
 			argv[j++] = argv[i];
@@ -521,6 +525,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 		start_number = 1;
 	if (numbered && keep_subject)
 		die ("-n and -k are mutually exclusive.");
+	if (keep_subject && subject_prefix)
+		die ("--subject-prefix and -k are mutually exclusive.");
 
 	argc = setup_revisions(argc, argv, &rev, "HEAD");
 	if (argc > 1)
log-tree.c +10 -4
index 8797aa1..dad5513 100644
@@ -165,14 +165,20 @@ void show_log(struct rev_info *opt, const char *sep)
 		if (opt->total > 0) {
 			static char buffer[64];
 			snprintf(buffer, sizeof(buffer),
-					"Subject: [PATCH %0*d/%d] ",
+					"Subject: [%s %0*d/%d] ",
+					opt->subject_prefix,
 					digits_in_number(opt->total),
 					opt->nr, opt->total);
 			subject = buffer;
-		} else if (opt->total == 0)
-			subject = "Subject: [PATCH] ";
-		else
+		} else if (opt->total == 0) {
+			static char buffer[256];
+			snprintf(buffer, sizeof(buffer),
+					"Subject: [%s] ",
+					opt->subject_prefix);
+			subject = buffer;
+		} else {
 			subject = "Subject: ";
+		}
 
 		printf("From %s Mon Sep 17 00:00:00 2001\n", sha1);
 		if (opt->message_id)
revision.h +1 -0
index 55e6b53..5f3f628 100644
@@ -78,6 +78,7 @@ struct rev_info {
 	const char	*add_signoff;
 	const char	*extra_headers;
 	const char	*log_reencode;
+	const char	*subject_prefix;
 	int		no_inline;
 
 	/* Filter by commit log message */
Signature · 1 line
1.5.1
#2 lore raw

PATCH 2/2 Add testcase for format-patch --subject-prefix (take 3)

From: Robin H. Johnson <[email protected]>

Add testcase for format-patch --subject-prefix support.

---
 t/t4013-diff-various.sh                            |    1 +
 ...tdout_--subject-prefix=TESTCASE_initial..master |  164 ++++++++++++++++++++
 2 files changed, 165 insertions(+), 0 deletions(-)
 create mode 100644 t/t4013/diff.format-patch_--inline_--stdout_--subject-prefix=TESTCASE_initial..master
t/t4013-diff-various.sh +1 -0
index 488e075..8f4c29a 100755
@@ -241,6 +241,7 @@ format-patch --attach --stdout initial..master
 format-patch --inline --stdout initial..side
 format-patch --inline --stdout initial..master^
 format-patch --inline --stdout initial..master
+format-patch --inline --stdout --subject-prefix=TESTCASE initial..master
 
 diff --abbrev initial..side
 diff -r initial..side
t/t4013/diff.format-patch_--inline_--stdout_--subject-prefix=TESTCASE_initial..master new file +164 -0

164 lines not on this page · raw message

Signature · 1 line
1.5.1
#3 lore raw
In reply to Robin H. Johnson
Quoted 8 lines · Robin H\. Johnson

Add a new option to git-format-patch, entitled --subject-prefix that allows control of the subject prefix '[PATCH]'. Using this option, the text 'PATCH' is replaced with whatever input is provided to the option. This allows easily generating patches like '[PATCH 2.6.21-rc3]' or properly numbered series like '[-mm3 PATCH N/M]'.

1/2 - Implementation and documentation
2/2 - Test case

I suspect this is a job for send-email, not format-patch. List?

#4 lore raw
Quoted 8 lines · Junio C Hamano
Quoted 6 lines · Robin H\. Johnson

Add a new option to git-format-patch, entitled --subject-prefix that allows control of the subject prefix '[PATCH]'. Using this option, the text 'PATCH' is replaced with whatever input is provided to the option. This allows easily generating patches like '[PATCH 2.6.21-rc3]' or properly numbered series like '[-mm3 PATCH N/M]'.

Quoted 4 lines
Quoted 2 lines

1/2 - Implementation and documentation
2/2 - Test case

I suspect this is a job for send-email, not format-patch. List?

Surely though, send-email is simply a helper for sending patches generated by format-patch? Is there any reason to deny the ability to set the prefix to those who don't use send-email but do use format-patch? (Personally I found send-email to be cumbersome and confusing, so I've stopped using it ...)

It's format-patch that applies the current "[PATCH]" prefix anyway ...

Signature · 5 lines
Julian

 ---
Death, when unnecessary, is a tragic thing.
		-- Flint, "Requiem for Methuselah", stardate 5843.7
#5 lore raw
Quoted 15 lines · Julian Phillips
Quoted 8 lines · Junio C Hamano
Quoted 6 lines · Robin H\. Johnson

Add a new option to git-format-patch, entitled --subject-prefix that allows control of the subject prefix '[PATCH]'. Using this option, the text 'PATCH' is replaced with whatever input is provided to the option. This allows easily generating patches like '[PATCH 2.6.21-rc3]' or properly numbered series like '[-mm3 PATCH N/M]'.

Quoted 4 lines
Quoted 2 lines

1/2 - Implementation and documentation
2/2 - Test case

I suspect this is a job for send-email, not format-patch. List?

Quoted 7 lines

Surely though, send-email is simply a helper for sending patches generated by format-patch? Is there any reason to deny the ability to set the prefix to those who don't use send-email but do use format-patch? (Personally I found send-email to be cumbersome and confusing, so I've stopped using it ...)

It's format-patch that applies the current "[PATCH]" prefix anyway ...

I was more worried about people's scripts who postprocess format-patch output, relying on the '[PATCH]' to be there. But they should be using -k to suppress it anyway, so this addition should be Ok.

Somebody needs to verify that mailinfo groks e-mails correctly even when they have "Subject: [random garbage] title" though.

#6 lore raw
Quoted 6 lines · Junio C Hamano
Quoted 4 lines · Julian Phillips
Quoted 2 lines · Junio C Hamano

"Robin H\. Johnson" <[email protected]> writes:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Add a new option to git-format-patch, entitled --subject-prefix that allows control of the subject prefix '[PATCH]'. Using this option, the text 'PATCH' is replaced with whatever input is provided to the option. This allows easily generating patches like '[PATCH 2.6.21-rc3]' or properly numbered series like '[-mm3 PATCH N/M]'.

1/2 - Implementation and documentation
2/2 - Test case

Gaah.

I applied it, pushed the results out and then found breakage. How much I hate these random and non-essential "mean well to enhance usability" patches X-<...

In the meantime, I think this should fix it. Please test well.

-- >8 --
Fix git {log,show,...} --pretty=email

An earlier --subject-prefix forgot that format-patch is not the only codepath that added the "[PATCH]" prefix, breaking everybody else in the log family.

---
 builtin-log.c |    1 -
 revision.c    |    1 +
 2 files changed, 1 insertions(+), 1 deletions(-)
builtin-log.c +0 -1
index 4a4890a..ffc269a 100644
@@ -435,7 +435,6 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 	rev.ignore_merges = 1;
 	rev.diffopt.msg_sep = "";
 	rev.diffopt.recursive = 1;
-	rev.subject_prefix = "PATCH";
 
 	rev.extra_headers = extra_headers;
 
revision.c +1 -0
index 486393c..37f1eab 100644
@@ -567,6 +567,7 @@ void init_revisions(struct rev_info *revs, const char *prefix)
 	revs->min_age = -1;
 	revs->skip_count = -1;
 	revs->max_count = -1;
+	revs->subject_prefix = "PATCH";
 
 	revs->prune_fn = NULL;
 	revs->prune_data = NULL;