git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 0/6] teach branch-specific options for format-patch

From
Denton Liu <liu.denton@gmail.com>
Date
May 17, 2019, 00:27 UTC
Message-ID
<cover.1558052674.git.liu.denton@gmail.com>
In-Reply-To
<cover.1557072929.git.liu.denton@gmail.com>
Hi all,

I thought a lot about building the branch-specific include option but I opted against this because `format.<name>.coverSubject` is a branch-exclusive config option, whereas it doesn't make sense to have a `format.coverSubject` option.

Thus, if we pursue this, we *need* to have a `format.<name>.*` section so let's not deal with the complexity of buliding a generic include system for now.

Also, I might consider adding a `format.<name>.outputDirectory` option in the future but let's see what kind of comments this patchset gets.

Changes since v1:
* Used format.<branch-name>.* variables instead of branch.<branch-name>.*
Denton Liu (6):
  t4014: clean up style
  Doc: add more detail for git-format-patch
  format-patch: make cover letter subject configurable
  format-patch: move extra_headers logic later
  string-list: create string_list_append_all
  format-patch: read branch-specific To: and Cc: headers
 Documentation/config/format.txt    |  12 +-
 Documentation/git-format-patch.txt |  33 +-
 builtin/branch.c                   |  16 +-
 builtin/log.c                      | 162 +++++--
 string-list.c                      |   9 +
 string-list.h                      |   7 +
 t/t3200-branch.sh                  |   8 +-
 t/t4014-format-patch.sh            | 708 +++++++++++++++++------------
 t/t9902-completion.sh              |   5 +-
 9 files changed, 608 insertions(+), 352 deletions(-)
Interdiff against v1:
diff --git a/Documentation/config/branch.txt b/Documentation/config/branch.txt
index d292210cf6..8f4b3faadd 100644
--- a/Documentation/config/branch.txt
+++ b/Documentation/config/branch.txt
@@ -100,13 +100,3 @@ branch.<name>.description::
 	`git branch --edit-description`. Branch description is
 	automatically added in the format-patch cover letter or
 	request-pull summary.
-
-branch.<name>.coverSubject::
-	When format-patch generates a cover letter, use the specified
-	subject for the cover letter instead of the generic template.
-
-branch.<name>.to::
-branch.<name>.cc::
-	Additional recipients to include in a patch to be submitted
-	by mail.  See the --to and --cc options in
-	linkgit:git-format-patch[1].
diff --git a/Documentation/config/format.txt b/Documentation/config/format.txt
index dc77941c48..d387451573 100644
--- a/Documentation/config/format.txt
+++ b/Documentation/config/format.txt
@@ -28,14 +28,22 @@ format.headers::
 
 format.to::
 format.cc::
+format.<branch-name>.to::
+format.<branch-name>.cc::
 	Additional recipients to include in a patch to be submitted
-	by mail.  See the --to and --cc options in
-	linkgit:git-format-patch[1].
+	by mail.  For the <branch-name> options, the recipients are only
+	included if patches are generated for the given <branch-name>.
+	See the --to and --cc options in linkgit:git-format-patch[1].
 
 format.subjectPrefix::
 	The default for format-patch is to output files with the '[PATCH]'
 	subject prefix. Use this variable to change that prefix.
 
+format.<branch-name>.coverSubject::
+	When format-patch generates a cover letter for the given
+	<branch-name>, use the specified subject for the cover letter
+	instead of the generic template.
+
 format.signature::
 	The default for format-patch is to output a signature containing
 	the Git version number. Use this variable to change that default.
diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt
index 1c972f683a..4e826010f6 100644
--- a/Documentation/git-format-patch.txt
+++ b/Documentation/git-format-patch.txt
@@ -199,7 +199,7 @@ will want to ensure that threading is disabled for `git send-email`.
 	Add a `To:` header to the email headers. This is in addition
 	to any configured headers, and may be used multiple times. The
 	emails given will be used along with any emails given by
-	`format.to` and `branch.<name>.to` configurations.
+	`format.to` and `format.<branch-name>.to` configurations.
 	The negated form `--no-to` discards all `To:` headers added so
 	far (from config or command line).
 
@@ -207,7 +207,7 @@ will want to ensure that threading is disabled for `git send-email`.
 	Add a `Cc:` header to the email headers. This is in addition
 	to any configured headers, and may be used multiple times. The
 	emails given will be used along with any emails given by
-	`format.cc` and `branch.<name>.cc` configurations.
+	`format.cc` and `format.<branch-name>.cc` configurations.
 	The negated form `--no-cc` discards all `Cc:` headers added so
 	far (from config or command line).
 
@@ -355,7 +355,7 @@ In addition, for a specific branch, you can specify a custom cover
 letter subject, and add additional "To:" or "Cc:" headers.
 
 ------------
-[branch "branch-name"]
+[format "branch-name"]
 	coverSubject = "subject for branch-name only"
 	to = <email>
 	cc = <email>
diff --git a/branch.c b/branch.c
index 83cd441790..643694542a 100644
--- a/branch.c
+++ b/branch.c
@@ -163,11 +163,11 @@ static void setup_tracking(const char *new_ref, const char *orig_ref,
 	free(tracking.src);
 }
 
-static int read_branch_config(struct strbuf *buf, const char *branch_name, const char *key)
+int read_branch_desc(struct strbuf *buf, const char *branch_name)
 {
 	char *v = NULL;
 	struct strbuf name = STRBUF_INIT;
-	strbuf_addf(&name, "branch.%s.%s", branch_name, key);
+	strbuf_addf(&name, "branch.%s.description", branch_name);
 	if (git_config_get_string(name.buf, &v)) {
 		strbuf_release(&name);
 		return -1;
@@ -178,16 +178,6 @@ static int read_branch_config(struct strbuf *buf, const char *branch_name, const
 	return 0;
 }
 
-int read_branch_desc(struct strbuf *buf, const char *branch_name)
-{
-	return read_branch_config(buf, branch_name, "description");
-}
-
-int read_branch_subject(struct strbuf *buf, const char *branch_name)
-{
-	return read_branch_config(buf, branch_name, "coversubject");
-}
-
 /*
  * Check if 'name' can be a valid name for a branch; die otherwise.
  * Return 1 if the named branch already exists; return 0 otherwise.
diff --git a/branch.h b/branch.h
index 363a4fae9d..6f38db14e9 100644
--- a/branch.h
+++ b/branch.h
@@ -79,11 +79,6 @@ int install_branch_config(int flag, const char *local, const char *origin, const
  */
 int read_branch_desc(struct strbuf *, const char *branch_name);
 
-/*
- * Read branch subject
- */
-extern int read_branch_subject(struct strbuf *, const char *branch_name);
-
 /*
  * Check if a branch is checked out in the main worktree or any linked
  * worktree and die (with a message describing its checkout location) if
diff --git a/builtin/branch.c b/builtin/branch.c
index d4359b33ac..367e1fc9bc 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -178,12 +178,22 @@ static int check_branch_commit(const char *branchname, const char *refname,
 	return 0;
 }
 
+static const char *branch_specific_config[] = {
+	"branch",
+	"format",
+	NULL
+};
+
 static void delete_branch_config(const char *branchname)
 {
 	struct strbuf buf = STRBUF_INIT;
-	strbuf_addf(&buf, "branch.%s", branchname);
-	if (git_config_rename_section(buf.buf, NULL) < 0)
-		warning(_("Update of config-file failed"));
+	int i;
+	for (i = 0; branch_specific_config[i]; i++) {
+		strbuf_addf(&buf, "%s.%s", branch_specific_config[i], branchname);
+		if (git_config_rename_section(buf.buf, NULL) < 0)
+			warning(_("Update of config-file failed"));
+		strbuf_reset(&buf);
+	}
 	strbuf_release(&buf);
 }
 
diff --git a/builtin/log.c b/builtin/log.c
index 3adc942b8c..e1d793577d 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1032,6 +1032,21 @@ static void show_diffstat(struct rev_info *rev,
 	fprintf(rev->diffopt.file, "\n");
 }
 
+static int read_branch_subject(struct strbuf *buf, const char *branch_name)
+{
+	char *v = NULL;
+	struct strbuf name = STRBUF_INIT;
+	strbuf_addf(&name, "format.%s.coverSubject", branch_name);
+	if (git_config_get_string(name.buf, &v)) {
+		strbuf_release(&name);
+		return -1;
+	}
+	strbuf_addstr(buf, v);
+	free(v);
+	strbuf_release(&name);
+	return 0;
+}
+
 static void add_branch_headers(struct rev_info *rev, const char *branch_name)
 {
 	struct strbuf buf = STRBUF_INIT;
@@ -1064,7 +1079,7 @@ static void add_branch_headers(struct rev_info *rev, const char *branch_name)
 	 */
 
 	if (!to_cleared) {
-		strbuf_addf(&buf, "branch.%s.to", branch_name);
+		strbuf_addf(&buf, "format.%s.to", branch_name);
 		values = git_config_get_value_multi(buf.buf);
 		if (values)
 			string_list_append_all(&extra_to, values);
@@ -1072,7 +1087,7 @@ static void add_branch_headers(struct rev_info *rev, const char *branch_name)
 
 	if (!cc_cleared) {
 		strbuf_reset(&buf);
-		strbuf_addf(&buf, "branch.%s.cc", branch_name);
+		strbuf_addf(&buf, "format.%s.cc", branch_name);
 		values = git_config_get_value_multi(buf.buf);
 		if (values)
 			string_list_append_all(&extra_cc, values);
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index e9ad50b66d..9ae3da888e 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -782,9 +782,15 @@ test_expect_success 'test tracking setup via --track but deeper' '
 '
 
 test_expect_success 'test deleting branch deletes branch config' '
+	git config format.my7.coverSubject "cover subject" &&
+	git config format.my7.to "To Me <to@example.com>" &&
+	git config format.my7.cc "Cc Me <cc@example.com>" &&
 	git branch -d my7 &&
 	test -z "$(git config branch.my7.remote)" &&
-	test -z "$(git config branch.my7.merge)"
+	test -z "$(git config branch.my7.merge)" &&
+	test -z "$(git config format.my7.coverSubject)"
+	test -z "$(git config format.my7.to)" &&
+	test -z "$(git config format.my7.cc)"
 '
 
 test_expect_success 'test deleting branch without config' '
diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
index 5d6c85489e..9c527510c3 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -237,7 +237,7 @@ test_expect_failure 'configuration To: header (rfc2047)' '
 test_expect_success 'branch-specific configuration To: header (ascii)' '
 
 	test_unconfig format.to &&
-	git config branch.side.to "R E Cipient <rcipient@example.com>" &&
+	git config format.side.to "R E Cipient <rcipient@example.com>" &&
 	git format-patch --stdout master..side >patch10 &&
 	sed -e "/^\$/q" patch10 >hdrs10 &&
 	grep "^To: R E Cipient <rcipient@example.com>\$" hdrs10
@@ -245,7 +245,7 @@ test_expect_success 'branch-specific configuration To: header (ascii)' '
 
 test_expect_failure 'branch-specific configuration To: header (rfc822)' '
 
-	git config branch.side.to "R. E. Cipient <rcipient@example.com>" &&
+	git config format.side.to "R. E. Cipient <rcipient@example.com>" &&
 	git format-patch --stdout master..side >patch10 &&
 	sed -e "/^\$/q" patch10 >hdrs10 &&
 	grep "^To: \"R. E. Cipient\" <rcipient@example.com>\$" hdrs10
@@ -253,7 +253,7 @@ test_expect_failure 'branch-specific configuration To: header (rfc822)' '
 
 test_expect_failure 'branch-specific configuration To: header (rfc2047)' '
 
-	git config branch.side.to "R Ä Cipient <rcipient@example.com>" &&
+	git config format.side.to "R Ä Cipient <rcipient@example.com>" &&
 	git format-patch --stdout master..side >patch10 &&
 	sed -e "/^\$/q" patch10 >hdrs10 &&
 	grep "^To: =?UTF-8?q?R=20=C3=84=20Cipient?= <rcipient@example.com>\$" hdrs10
@@ -265,10 +265,10 @@ test_expect_success 'all recipients included from all sources' '
 	git config --add format.to "Format To2 <formatto2@example.com>" &&
 	git config format.cc "Format Cc1 <formatcc1@example.com>" &&
 	git config --add format.cc "Format Cc2 <formatcc2@example.com>" &&
-	git config branch.side.to "Branch To1 <branchto1@example.com>" &&
-	git config --add branch.side.to "Branch To2 <branchto2@example.com>" &&
-	git config branch.side.cc "Branch Cc1 <branchcc1@example.com>" &&
-	git config --add branch.side.cc "Branch Cc2 <branchcc2@example.com>" &&
+	git config format.side.to "Branch To1 <branchto1@example.com>" &&
+	git config --add format.side.to "Branch To2 <branchto2@example.com>" &&
+	git config format.side.cc "Branch Cc1 <branchcc1@example.com>" &&
+	git config --add format.side.cc "Branch Cc2 <branchcc2@example.com>" &&
 	cat <<-\EOF >expect &&
 	To: Format To1 <formatto1@example.com>,
 	    Format To2 <formatto2@example.com>,
@@ -345,7 +345,7 @@ test_expect_success '--no-to overrides config.to' '
 
 	git config --replace-all format.to \
 		"R E Cipient <rcipient@example.com>" &&
-	git config --replace-all branch.side.to \
+	git config --replace-all format.side.to \
 		"B R Anch <branch@example.com>" &&
 	git format-patch --no-to --stdout master..side >patch11 &&
 	sed -e "/^\$/q" patch11 >hdrs11 &&
@@ -358,7 +358,7 @@ test_expect_success '--no-to and --to replaces config.to' '
 
 	git config --replace-all format.to \
 		"Someone <someone@out.there>" &&
-	git config --replace-all branch.side.to \
+	git config --replace-all format.side.to \
 		"B R Anch2 <branch2@example.com>" &&
 	git format-patch --no-to --to="Someone Else <else@out.there>" \
 		--stdout master..side >patch12 &&
@@ -373,7 +373,7 @@ test_expect_success '--no-cc overrides config.cc' '
 
 	git config --replace-all format.cc \
 		"C E Cipient <rcipient@example.com>" &&
-	git config --replace-all branch.side.cc \
+	git config --replace-all format.side.cc \
 		"B R Anch3 <branch3@example.com>" &&
 	git format-patch --no-cc --stdout master..side >patch13 &&
 	sed -e "/^\$/q" patch13 >hdrs13 &&
@@ -1538,7 +1538,7 @@ test_expect_success 'format patch ignores color.ui' '
 '
 
 test_expect_success 'cover letter with config subject' '
-	test_config branch.rebuild-1.coverSubject "config subject" &&
+	test_config format.rebuild-1.coverSubject "config subject" &&
 	git checkout rebuild-1 &&
 	git format-patch --stdout --cover-letter master >actual &&
 	grep "Subject: \[PATCH 0/2\] config subject" actual
@@ -1551,7 +1551,7 @@ test_expect_success 'cover letter with command-line subject' '
 '
 
 test_expect_success 'cover letter with command-line subject overrides config' '
-	test_config branch.rebuild-1.coverSubject "config subject" &&
+	test_config format.rebuild-1.coverSubject "config subject" &&
 	git checkout rebuild-1 &&
 	git format-patch --stdout --cover-letter --cover-subject "command-line subject" master >actual &&
 	grep "Subject: \[PATCH 0/2\] command-line subject" actual
-- 
2.21.0.1049.geb646f7864
Previous: Johannes SchindelinNext: Denton Liu
Message 26 of 59 in “teach branch-specific options for format-patch”
  1. 0/7 teach branch-specific options for format-patchDenton Liu, May 5, 2019
  2. 1/7 t4014: clean up styleDenton Liu, May 5, 2019
  3. 2/7 Doc: add more detail for git-format-patchDenton Liu, May 5, 2019
  4. 3/7 branch.c: extract read_branch_config functionDenton Liu, May 5, 2019
  5. 4/7 format-patch: make cover letter subject configurableDenton Liu, May 5, 2019
  6. 5/7 format-patch: move extra_headers logic laterDenton Liu, May 5, 2019
  7. 6/7 string-list: create string_list_append_allDenton Liu, May 5, 2019
  8. 7/7 format-patch: read branch-specific To: and Cc: headersDenton Liu, May 5, 2019
  9. Junio C HamanoMay 7, 2019
  10. Denton LiuMay 7, 2019
  11. Junio C HamanoMay 7, 2019
  12. Denton LiuMay 7, 2019
  13. Ævar Arnfjörð BjarmasonMay 7, 2019
  14. Junio C HamanoMay 8, 2019
  15. config: learn the "onbranch:" includeIf conditionDenton Liu, May 31, 2019
  16. Johannes SchindelinMay 31, 2019
  17. Denton LiuMay 31, 2019
  18. Johannes SchindelinMay 31, 2019
  19. Denton LiuMay 31, 2019
  20. config: learn the "onbranch:" includeIf conditionDenton Liu, May 31, 2019
  21. Johannes SchindelinMay 31, 2019
  22. Johannes SchindelinJun 5, 2019
  23. Duy NguyenJun 5, 2019
  24. config: learn the "onbranch:" includeIf conditionDenton Liu, Jun 5, 2019
  25. Johannes SchindelinJun 6, 2019
  26. 0/6 teach branch-specific options for format-patchDenton Liu, May 17, 2019
  27. 1/6 t4014: clean up styleDenton Liu, May 17, 2019
  28. 2/6 Doc: add more detail for git-format-patchDenton Liu, May 17, 2019
  29. 3/6 format-patch: make cover letter subject configurableDenton Liu, May 17, 2019
  30. 4/6 format-patch: move extra_headers logic laterDenton Liu, May 17, 2019
  31. 5/6 string-list: create string_list_append_allDenton Liu, May 17, 2019
  32. 6/6 format-patch: read branch-specific To: and Cc: headersDenton Liu, May 17, 2019
  33. Junio C HamanoMay 17, 2019
  34. Denton LiuMay 17, 2019
  35. Denton LiuMay 17, 2019
  36. 0/8 teach branch-specific options for format-patchDenton Liu, May 22, 2019
  37. 1/8 t4014: clean up styleDenton Liu, May 22, 2019
  38. 2/8 Doc: add more detail for git-format-patchDenton Liu, May 22, 2019
  39. 3/8 format-patch: infer cover letter from branch descriptionDenton Liu, May 22, 2019
  40. 4/8 format-patch: move extra_headers logic laterDenton Liu, May 22, 2019
  41. 5/8 string-list: create string_list_append_allDenton Liu, May 22, 2019
  42. 6/8 format-patch: read branch-specific To: and Cc: headersDenton Liu, May 22, 2019
  43. 7/8 format-patch: move output_directory logic laterDenton Liu, May 22, 2019
  44. 8/8 format-patch: read branch-specific output directoryDenton Liu, May 22, 2019
  45. Denton LiuMay 31, 2019
  46. 0/8 teach branch-specific options for format-patchDenton Liu, Jun 14, 2019
  47. 1/8 t4014: clean up styleDenton Liu, Jun 14, 2019
  48. 2/8 Doc: add more detail for git-format-patchDenton Liu, Jun 14, 2019
  49. 3/8 format-patch: infer cover letter from branch descriptionDenton Liu, Jun 14, 2019
  50. 4/8 format-patch: move extra_headers logic laterDenton Liu, Jun 14, 2019
  51. 6/8 format-patch: read branch-specific To: and Cc: headersDenton Liu, Jun 14, 2019
  52. 5/8 string-list: create string_list_append_allDenton Liu, Jun 14, 2019
  53. 8/8 format-patch: read branch-specific output directoryDenton Liu, Jun 14, 2019
  54. 7/8 format-patch: move output_directory logic laterDenton Liu, Jun 14, 2019
  55. 0/3 format-patch: learn --infer-cover-subject option (also t4014 cleanup)Denton Liu, Oct 15, 2019
  56. 1/3 format-patch: replace erroneous and conditionDenton Liu, Oct 15, 2019
  57. 2/3 format-patch: use enum variablesDenton Liu, Oct 15, 2019
  58. 3/3 format-patch: teach --cover-from-description optionDenton Liu, Oct 15, 2019
  59. Junio C HamanoOct 16, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.