Skip to contentSkip to conversation

format-patch: Add configuration and off switch for --numbered

PATCH In review Brian Gernhardt 2 participants 4 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 format-patch: Add configuration and off switch for --numbered

format.numbered is a tri-state variable. Boolean values enable or disable numbering by default and "auto" enables number when outputting more than one patch.

--no-numbered (short: -N) will disable numbering.

---

Pick your own numbering adventure. Should make everyone happy, but will probably do the exact opposite. So it goes.

 Documentation/config.txt           |    6 ++++++
 Documentation/git-format-patch.txt |   12 ++++++++----
 builtin-log.c                      |   19 ++++++++++++++++++-
 3 files changed, 32 insertions(+), 5 deletions(-)
Documentation/config.txt +6 -0
index edf50cd..c2f9f14 100644
@@ -432,6 +432,12 @@ fetch.unpackLimit::
 	pack from a push can make the push operation complete faster,
 	especially on slow filesystems.
 
+format.numbered::
+	A boolean which can enable sequence numbers in patch subjects.
+	Seting this option to "auto" will enable it only if there is
+	more than one patch.  See --numbered option in
+	gitlink:git-format-patch[1].
+
 format.headers::
 	Additional email headers to include in a patch to be submitted
 	by mail.  See gitlink:git-format-patch[1].
Documentation/git-format-patch.txt +8 -4
index f0617ef..92c0ab6 100644
@@ -9,7 +9,7 @@ git-format-patch - Prepare patches for e-mail submission
 SYNOPSIS
 --------
 [verse]
-'git-format-patch' [-n | -k] [-o <dir> | --stdout] [--thread]
+'git-format-patch' [-n | -N | -k] [-o <dir> | --stdout] [--thread]
                    [--attach[=<boundary>] | --inline[=<boundary>]]
                    [-s | --signoff] [<common diff options>]
                    [--start-number <n>] [--numbered-files]
@@ -77,6 +77,9 @@ include::diff-options.txt[]
 -n|--numbered::
 	Name output in '[PATCH n/m]' format.
 
+-N|--no-numbered::
+	Name output in '[PATCH]' format.
+
 --start-number <n>::
 	Start numbering the patches at <n> instead of 1.
 
@@ -142,15 +145,16 @@ not add any suffix.
 
 CONFIGURATION
 -------------
-You can specify extra mail header lines to be added to each
-message in the repository configuration.  You can also specify
-new defaults for the subject prefix and file suffix.
+You can specify extra mail header lines to be added to each message
+in the repository configuration, new defaults for the subject prefix
+and file suffix, and number patches when outputting more than one.
 
 ------------
 [format]
         headers = "Organization: git-foo\n"
         subjectprefix = CHANGE
         suffix = .txt
+        numbered = auto
 ------------
 
 
builtin-log.c +18 -1
index e8b982d..22afa1a 100644
@@ -273,6 +273,8 @@ static int istitlechar(char c)
 static char *extra_headers = NULL;
 static int extra_headers_size = 0;
 static const char *fmt_patch_suffix = ".patch";
+static int numbered = 0;
+static int auto_number = 0;
 
 static int git_format_config(const char *var, const char *value)
 {
@@ -297,6 +299,15 @@ static int git_format_config(const char *var, const char *value)
 	if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {
 		return 0;
 	}
+	if (!strcmp(var, "format.numbered")) {
+		if (!strcasecmp(value, "auto")) {
+			auto_number = 1;
+			return 0;
+		}
+
+		numbered = git_config_bool(var, value);
+		return 0;
+	}
 
 	return git_log_config(var, value);
 }
@@ -466,7 +477,6 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 	struct rev_info rev;
 	int nr = 0, total, i, j;
 	int use_stdout = 0;
-	int numbered = 0;
 	int start_number = -1;
 	int keep_subject = 0;
 	int numbered_files = 0;		/* _just_ numbers */
@@ -503,6 +513,11 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 		else if (!strcmp(argv[i], "-n") ||
 				!strcmp(argv[i], "--numbered"))
 			numbered = 1;
+		else if (!strcmp(argv[i], "-N") ||
+				!strcmp(argv[i], "--no-numbered")) {
+			numbered = 0;
+			auto_number = 0;
+		}
 		else if (!prefixcmp(argv[i], "--start-number="))
 			start_number = strtol(argv[i] + 15, NULL, 10);
 		else if (!strcmp(argv[i], "--numbered-files"))
@@ -642,6 +657,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 		list[nr - 1] = commit;
 	}
 	total = nr;
+	if (!keep_subject && auto_number && total > 1)
+		numbered = 1;
 	if (numbered)
 		rev.total = total + start_number - 1;
 	rev.add_signoff = add_signoff;
Signature · 1 line
1.5.3.5.529.ge3d6d-dirty
#2 lore raw
Quoted 1 line · Junio C Hamano

The change looks good. Tests needed.

Thought so. Somebody's not happy. ;-)

I was going to modify the existing tests for --numbered, but discovered that there were none. Having nothing to start with, I didn't add.

That said, I'll try to hack something up.

~~ Brian

#3 lore raw

[PATCH 2/1] format-patch: Test --[no-]numbered and format.numbered

Just because there wasn't a test for --numbered isn't a good reason not to test format.numbered. So now we test both.

---

And here's that something I hacked up. Hmm... that doesn't sound sanitary.

As a side note, send-email is hard to troubleshoot. Is there a way to get it to give more than "your setup doesn't work"? And is the pile of warnings (mostly "Use of uninitialized value") in Term::Readline just a problem in my setup? I tried to use it instead of mutt and did not have a happy experience.

 t/t4021-format-patch-numbered.sh |  106 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 106 insertions(+), 0 deletions(-)
 create mode 100755 t/t4021-format-patch-numbered.sh
t/t4021-format-patch-numbered.sh new file +106 -0
new file mode 100755
index 0000000..43d64bb
@@ -0,0 +1,106 @@
+#!/bin/sh
+#
+# Copyright (c) 2006 Brian C Gernhardt
+#
+
+test_description='Format-patch numbering options'
+
+. ./test-lib.sh
+
+test_expect_success setup '
+
+	echo A > file &&
+	git add file &&
+	git commit -m First &&
+
+	echo B >> file &&
+	git commit -a -m Second &&
+
+	echo C >> file &&
+	git commit -a -m Third
+
+'
+
+# Each of these gets used multiple times.
+
+test_num_no_numbered() {
+	cnt=$(grep "^Subject: \[PATCH\]" $1 | wc -l) &&
+	test $cnt = $2
+}
+
+test_single_no_numbered() {
+	test_num_no_numbered $1 1
+}
+
+test_no_numbered() {
+	test_num_no_numbered $1 2
+}
+
+test_single_numbered() {
+	grep "^Subject: \[PATCH 1/1\]" $1
+}
+
+test_numbered() {
+	grep "^Subject: \[PATCH 1/2\]" $1 &&
+	grep "^Subject: \[PATCH 2/2\]" $1
+}
+
+test_expect_success 'Default: no numbered' '
+
+	git format-patch --stdout HEAD~2 >patch0 &&
+	test_no_numbered patch0
+
+'
+
+test_expect_success 'Use --numbered' '
+
+	git format-patch --numbered --stdout HEAD~2 >patch1 &&
+	test_numbered patch1
+
+'
+
+test_expect_success 'format.numbered = true' '
+
+	git config format.numbered true &&
+	git format-patch --stdout HEAD~2 >patch2 &&
+	test_numbered patch2
+
+'
+
+test_expect_success 'format.numbered && single patch' '
+
+	git format-patch --stdout HEAD^ > patch3 &&
+	test_single_numbered patch3
+
+'
+
+test_expect_success 'format.numbered && --no-numbered' '
+
+	git format-patch --no-numbered --stdout HEAD~2 >patch4 &&
+	test_no_numbered patch4
+
+'
+
+test_expect_success 'format.numbered = auto' '
+
+	git config format.numbered auto
+	git format-patch --stdout HEAD~2 > patch5 &&
+	test_numbered patch5
+
+'
+
+test_expect_success 'format.numbered = auto && single patch' '
+
+	git format-patch --stdout HEAD^ > patch6 &&
+	test_single_no_numbered patch6
+
+'
+
+test_expect_success 'format.numbered = auto && --no-numbered' '
+
+	git format-patch --no-numbered --stdout HEAD~2 > patch7 &&
+	test_no_numbered patch7
+
+'
+
+test_done
Signature · 1 line
1.5.3.5.530.gcd7a