@matheusbsbs / matheus-bagliano / commits / a567fdcb01
Fork 0

format-patch: autonumber by default

format-patch is most commonly used for multiple patches at once when sending a patchset, in which case we want to number the patches; on the other hand, single patches are not usually expected to be numbered. In other words, the typical behavior expected from format-patch is the one obtained by enabling autonumber, so we set it to be the default. Users that want to disable numbering for a particular patchset can do so with the existing -N command-line switch. Users that want to change the default behavior can use the format.numbering config key. Signed-off-by: Brian Gernhardt <benji@silverinsanity.com> Test-updates-by: Jeff King <peff@peff.net> Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brian Gernhardt committed Oct 2, 2008 at 16:55 UTC a567fdcb016e8e882ec0a1e044c9caac8f70e693
15 files changed +298 -32
Documentation/config.txt
+5 -4
@@ -640,10 +640,11 @@ fetch.unpackLimit::
640 `transfer.unpackLimit` is used instead.
641
642 format.numbered::
643 - A boolean which can enable sequence numbers in patch subjects.
644 - Setting this option to "auto" will enable it only if there is
645 - more than one patch. See --numbered option in
646 - linkgit:git-format-patch[1].
643 + A boolean which can enable or disable sequence numbers in patch
644 + subjects. It defaults to "auto" which enables it only if there
645 + is more than one patch. It can be enabled or disabled for all
646 + messages by setting it to "true" or "false". See --numbered
647 + option in linkgit:git-format-patch[1].
648
649 format.headers::
650 Additional email headers to include in a patch to be submitted
Documentation/git-format-patch.txt
+5 -3
@@ -58,8 +58,10 @@ output, unless the --stdout option is specified.
58 If -o is specified, output files are created in <dir>. Otherwise
59 they are created in the current working directory.
60
61 -If -n is specified, instead of "[PATCH] Subject", the first line
62 -is formatted as "[PATCH n/m] Subject".
61 +By default, the subject of a single patch is "[PATCH] First Line" and
62 +the subject when multiple patches are output is "[PATCH n/m] First
63 +Line". To force 1/1 to be added for a single patch, use -n. To omit
64 +patch numbers from the subject, use -N
65
66 If given --thread, 'git-format-patch' will generate In-Reply-To and
67 References headers to make the second and subsequent patch mails appear
@@ -81,7 +83,7 @@ include::diff-options.txt[]
83
84 -n::
85 --numbered::
84 - Name output in '[PATCH n/m]' format.
86 + Name output in '[PATCH n/m]' format, even with a single patch.
87
88 -N::
89 --no-numbered::
builtin-log.c
+2 -1
@@ -426,7 +426,7 @@ static int istitlechar(char c)
426
427 static const char *fmt_patch_suffix = ".patch";
428 static int numbered = 0;
429 -static int auto_number = 0;
429 +static int auto_number = 1;
430
431 static char **extra_hdr;
432 static int extra_hdr_nr;
@@ -485,6 +485,7 @@ static int git_format_config(const char *var, const char *value, void *cb)
485 return 0;
486 }
487 numbered = git_config_bool(var, value);
488 + auto_number = auto_number && numbered;
489 return 0;
490 }
491
t/t4013-diff-various.sh
+3
@@ -236,12 +236,15 @@ show --patch-with-stat --summary side
236 format-patch --stdout initial..side
237 format-patch --stdout initial..master^
238 format-patch --stdout initial..master
239 +format-patch --stdout --no-numbered initial..master
240 +format-patch --stdout --numbered initial..master
241 format-patch --attach --stdout initial..side
242 format-patch --attach --stdout initial..master^
243 format-patch --attach --stdout initial..master
244 format-patch --inline --stdout initial..side
245 format-patch --inline --stdout initial..master^
246 format-patch --inline --stdout initial..master
247 +format-patch --inline --stdout initial..master
248 format-patch --inline --stdout --subject-prefix=TESTCASE initial..master
249 config format.subjectprefix DIFFERENT_PREFIX
250 format-patch --inline --stdout initial..master^^
t/t4013/diff.format-patch_--attach_--stdout_initial..master
+3 -3
@@ -2,7 +2,7 @@ $ git format-patch --attach --stdout initial..master
2 From 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44 Mon Sep 17 00:00:00 2001
3 From: A U Thor <author@example.com>
4 Date: Mon, 26 Jun 2006 00:01:00 +0000
5 -Subject: [PATCH] Second
5 +Subject: [PATCH 1/3] Second
6 MIME-Version: 1.0
7 Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n"
8
@@ -63,7 +63,7 @@ index 01e79c3..0000000
63 From 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 Mon Sep 17 00:00:00 2001
64 From: A U Thor <author@example.com>
65 Date: Mon, 26 Jun 2006 00:02:00 +0000
66 -Subject: [PATCH] Third
66 +Subject: [PATCH 2/3] Third
67 MIME-Version: 1.0
68 Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n"
69
@@ -111,7 +111,7 @@ index 0000000..b1e6722
111 From c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Mon Sep 17 00:00:00 2001
112 From: A U Thor <author@example.com>
113 Date: Mon, 26 Jun 2006 00:03:00 +0000
114 -Subject: [PATCH] Side
114 +Subject: [PATCH 3/3] Side
115 MIME-Version: 1.0
116 Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n"
117
t/t4013/diff.format-patch_--attach_--stdout_initial..master^
+2 -2
@@ -2,7 +2,7 @@ $ git format-patch --attach --stdout initial..master^
2 From 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44 Mon Sep 17 00:00:00 2001
3 From: A U Thor <author@example.com>
4 Date: Mon, 26 Jun 2006 00:01:00 +0000
5 -Subject: [PATCH] Second
5 +Subject: [PATCH 1/2] Second
6 MIME-Version: 1.0
7 Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n"
8
@@ -63,7 +63,7 @@ index 01e79c3..0000000
63 From 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 Mon Sep 17 00:00:00 2001
64 From: A U Thor <author@example.com>
65 Date: Mon, 26 Jun 2006 00:02:00 +0000
66 -Subject: [PATCH] Third
66 +Subject: [PATCH 2/2] Third
67 MIME-Version: 1.0
68 Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n"
69
t/t4013/diff.format-patch_--inline_--stdout_--subject-prefix=TESTCASE_initial..master
+3 -3
@@ -2,7 +2,7 @@ $ git format-patch --inline --stdout --subject-prefix=TESTCASE initial..master
2 From 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44 Mon Sep 17 00:00:00 2001
3 From: A U Thor <author@example.com>
4 Date: Mon, 26 Jun 2006 00:01:00 +0000
5 -Subject: [TESTCASE] Second
5 +Subject: [TESTCASE 1/3] Second
6 MIME-Version: 1.0
7 Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n"
8
@@ -63,7 +63,7 @@ index 01e79c3..0000000
63 From 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 Mon Sep 17 00:00:00 2001
64 From: A U Thor <author@example.com>
65 Date: Mon, 26 Jun 2006 00:02:00 +0000
66 -Subject: [TESTCASE] Third
66 +Subject: [TESTCASE 2/3] Third
67 MIME-Version: 1.0
68 Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n"
69
@@ -111,7 +111,7 @@ index 0000000..b1e6722
111 From c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Mon Sep 17 00:00:00 2001
112 From: A U Thor <author@example.com>
113 Date: Mon, 26 Jun 2006 00:03:00 +0000
114 -Subject: [TESTCASE] Side
114 +Subject: [TESTCASE 3/3] Side
115 MIME-Version: 1.0
116 Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n"
117
t/t4013/diff.format-patch_--inline_--stdout_initial..master
+3 -3
@@ -2,7 +2,7 @@ $ git format-patch --inline --stdout initial..master
2 From 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44 Mon Sep 17 00:00:00 2001
3 From: A U Thor <author@example.com>
4 Date: Mon, 26 Jun 2006 00:01:00 +0000
5 -Subject: [PATCH] Second
5 +Subject: [PATCH 1/3] Second
6 MIME-Version: 1.0
7 Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n"
8
@@ -63,7 +63,7 @@ index 01e79c3..0000000
63 From 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 Mon Sep 17 00:00:00 2001
64 From: A U Thor <author@example.com>
65 Date: Mon, 26 Jun 2006 00:02:00 +0000
66 -Subject: [PATCH] Third
66 +Subject: [PATCH 2/3] Third
67 MIME-Version: 1.0
68 Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n"
69
@@ -111,7 +111,7 @@ index 0000000..b1e6722
111 From c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Mon Sep 17 00:00:00 2001
112 From: A U Thor <author@example.com>
113 Date: Mon, 26 Jun 2006 00:03:00 +0000
114 -Subject: [PATCH] Side
114 +Subject: [PATCH 3/3] Side
115 MIME-Version: 1.0
116 Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n"
117
t/t4013/diff.format-patch_--inline_--stdout_initial..master^
+2 -2
@@ -2,7 +2,7 @@ $ git format-patch --inline --stdout initial..master^
2 From 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44 Mon Sep 17 00:00:00 2001
3 From: A U Thor <author@example.com>
4 Date: Mon, 26 Jun 2006 00:01:00 +0000
5 -Subject: [PATCH] Second
5 +Subject: [PATCH 1/2] Second
6 MIME-Version: 1.0
7 Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n"
8
@@ -63,7 +63,7 @@ index 01e79c3..0000000
63 From 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 Mon Sep 17 00:00:00 2001
64 From: A U Thor <author@example.com>
65 Date: Mon, 26 Jun 2006 00:02:00 +0000
66 -Subject: [PATCH] Third
66 +Subject: [PATCH 2/2] Third
67 MIME-Version: 1.0
68 Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n"
69
t/t4013/diff.format-patch_--stdout_--no-numbered_initial..master new
+127
@@ -0,0 +1,127 @@
1 +$ git format-patch --stdout --no-numbered initial..master
2 +From 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44 Mon Sep 17 00:00:00 2001
3 +From: A U Thor <author@example.com>
4 +Date: Mon, 26 Jun 2006 00:01:00 +0000
5 +Subject: [PATCH] Second
6 +
7 +This is the second commit.
8 +---
9 + dir/sub | 2 ++
10 + file0 | 3 +++
11 + file2 | 3 ---
12 + 3 files changed, 5 insertions(+), 3 deletions(-)
13 + delete mode 100644 file2
14 +
15 +diff --git a/dir/sub b/dir/sub
16 +index 35d242b..8422d40 100644
17 +--- a/dir/sub
18 ++++ b/dir/sub
19 +@@ -1,2 +1,4 @@
20 + A
21 + B
22 ++C
23 ++D
24 +diff --git a/file0 b/file0
25 +index 01e79c3..b414108 100644
26 +--- a/file0
27 ++++ b/file0
28 +@@ -1,3 +1,6 @@
29 + 1
30 + 2
31 + 3
32 ++4
33 ++5
34 ++6
35 +diff --git a/file2 b/file2
36 +deleted file mode 100644
37 +index 01e79c3..0000000
38 +--- a/file2
39 ++++ /dev/null
40 +@@ -1,3 +0,0 @@
41 +-1
42 +-2
43 +-3
44 +--
45 +g-i-t--v-e-r-s-i-o-n
46 +
47 +
48 +From 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 Mon Sep 17 00:00:00 2001
49 +From: A U Thor <author@example.com>
50 +Date: Mon, 26 Jun 2006 00:02:00 +0000
51 +Subject: [PATCH] Third
52 +
53 +---
54 + dir/sub | 2 ++
55 + file1 | 3 +++
56 + 2 files changed, 5 insertions(+), 0 deletions(-)
57 + create mode 100644 file1
58 +
59 +diff --git a/dir/sub b/dir/sub
60 +index 8422d40..cead32e 100644
61 +--- a/dir/sub
62 ++++ b/dir/sub
63 +@@ -2,3 +2,5 @@ A
64 + B
65 + C
66 + D
67 ++E
68 ++F
69 +diff --git a/file1 b/file1
70 +new file mode 100644
71 +index 0000000..b1e6722
72 +--- /dev/null
73 ++++ b/file1
74 +@@ -0,0 +1,3 @@
75 ++A
76 ++B
77 ++C
78 +--
79 +g-i-t--v-e-r-s-i-o-n
80 +
81 +
82 +From c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Mon Sep 17 00:00:00 2001
83 +From: A U Thor <author@example.com>
84 +Date: Mon, 26 Jun 2006 00:03:00 +0000
85 +Subject: [PATCH] Side
86 +
87 +---
88 + dir/sub | 2 ++
89 + file0 | 3 +++
90 + file3 | 4 ++++
91 + 3 files changed, 9 insertions(+), 0 deletions(-)
92 + create mode 100644 file3
93 +
94 +diff --git a/dir/sub b/dir/sub
95 +index 35d242b..7289e35 100644
96 +--- a/dir/sub
97 ++++ b/dir/sub
98 +@@ -1,2 +1,4 @@
99 + A
100 + B
101 ++1
102 ++2
103 +diff --git a/file0 b/file0
104 +index 01e79c3..f4615da 100644
105 +--- a/file0
106 ++++ b/file0
107 +@@ -1,3 +1,6 @@
108 + 1
109 + 2
110 + 3
111 ++A
112 ++B
113 ++C
114 +diff --git a/file3 b/file3
115 +new file mode 100644
116 +index 0000000..7289e35
117 +--- /dev/null
118 ++++ b/file3
119 +@@ -0,0 +1,4 @@
120 ++A
121 ++B
122 ++1
123 ++2
124 +--
125 +g-i-t--v-e-r-s-i-o-n
126 +
127 +$
t/t4013/diff.format-patch_--stdout_--numbered_initial..master new
+127
@@ -0,0 +1,127 @@
1 +$ git format-patch --stdout --numbered initial..master
2 +From 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44 Mon Sep 17 00:00:00 2001
3 +From: A U Thor <author@example.com>
4 +Date: Mon, 26 Jun 2006 00:01:00 +0000
5 +Subject: [PATCH 1/3] Second
6 +
7 +This is the second commit.
8 +---
9 + dir/sub | 2 ++
10 + file0 | 3 +++
11 + file2 | 3 ---
12 + 3 files changed, 5 insertions(+), 3 deletions(-)
13 + delete mode 100644 file2
14 +
15 +diff --git a/dir/sub b/dir/sub
16 +index 35d242b..8422d40 100644
17 +--- a/dir/sub
18 ++++ b/dir/sub
19 +@@ -1,2 +1,4 @@
20 + A
21 + B
22 ++C
23 ++D
24 +diff --git a/file0 b/file0
25 +index 01e79c3..b414108 100644
26 +--- a/file0
27 ++++ b/file0
28 +@@ -1,3 +1,6 @@
29 + 1
30 + 2
31 + 3
32 ++4
33 ++5
34 ++6
35 +diff --git a/file2 b/file2
36 +deleted file mode 100644
37 +index 01e79c3..0000000
38 +--- a/file2
39 ++++ /dev/null
40 +@@ -1,3 +0,0 @@
41 +-1
42 +-2
43 +-3
44 +--
45 +g-i-t--v-e-r-s-i-o-n
46 +
47 +
48 +From 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 Mon Sep 17 00:00:00 2001
49 +From: A U Thor <author@example.com>
50 +Date: Mon, 26 Jun 2006 00:02:00 +0000
51 +Subject: [PATCH 2/3] Third
52 +
53 +---
54 + dir/sub | 2 ++
55 + file1 | 3 +++
56 + 2 files changed, 5 insertions(+), 0 deletions(-)
57 + create mode 100644 file1
58 +
59 +diff --git a/dir/sub b/dir/sub
60 +index 8422d40..cead32e 100644
61 +--- a/dir/sub
62 ++++ b/dir/sub
63 +@@ -2,3 +2,5 @@ A
64 + B
65 + C
66 + D
67 ++E
68 ++F
69 +diff --git a/file1 b/file1
70 +new file mode 100644
71 +index 0000000..b1e6722
72 +--- /dev/null
73 ++++ b/file1
74 +@@ -0,0 +1,3 @@
75 ++A
76 ++B
77 ++C
78 +--
79 +g-i-t--v-e-r-s-i-o-n
80 +
81 +
82 +From c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Mon Sep 17 00:00:00 2001
83 +From: A U Thor <author@example.com>
84 +Date: Mon, 26 Jun 2006 00:03:00 +0000
85 +Subject: [PATCH 3/3] Side
86 +
87 +---
88 + dir/sub | 2 ++
89 + file0 | 3 +++
90 + file3 | 4 ++++
91 + 3 files changed, 9 insertions(+), 0 deletions(-)
92 + create mode 100644 file3
93 +
94 +diff --git a/dir/sub b/dir/sub
95 +index 35d242b..7289e35 100644
96 +--- a/dir/sub
97 ++++ b/dir/sub
98 +@@ -1,2 +1,4 @@
99 + A
100 + B
101 ++1
102 ++2
103 +diff --git a/file0 b/file0
104 +index 01e79c3..f4615da 100644
105 +--- a/file0
106 ++++ b/file0
107 +@@ -1,3 +1,6 @@
108 + 1
109 + 2
110 + 3
111 ++A
112 ++B
113 ++C
114 +diff --git a/file3 b/file3
115 +new file mode 100644
116 +index 0000000..7289e35
117 +--- /dev/null
118 ++++ b/file3
119 +@@ -0,0 +1,4 @@
120 ++A
121 ++B
122 ++1
123 ++2
124 +--
125 +g-i-t--v-e-r-s-i-o-n
126 +
127 +$
t/t4013/diff.format-patch_--stdout_initial..master
+3 -3
@@ -2,7 +2,7 @@ $ git format-patch --stdout initial..master
2 From 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44 Mon Sep 17 00:00:00 2001
3 From: A U Thor <author@example.com>
4 Date: Mon, 26 Jun 2006 00:01:00 +0000
5 -Subject: [PATCH] Second
5 +Subject: [PATCH 1/3] Second
6
7 This is the second commit.
8 ---
@@ -48,7 +48,7 @@ g-i-t--v-e-r-s-i-o-n
48 From 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 Mon Sep 17 00:00:00 2001
49 From: A U Thor <author@example.com>
50 Date: Mon, 26 Jun 2006 00:02:00 +0000
51 -Subject: [PATCH] Third
51 +Subject: [PATCH 2/3] Third
52
53 ---
54 dir/sub | 2 ++
@@ -82,7 +82,7 @@ g-i-t--v-e-r-s-i-o-n
82 From c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Mon Sep 17 00:00:00 2001
83 From: A U Thor <author@example.com>
84 Date: Mon, 26 Jun 2006 00:03:00 +0000
85 -Subject: [PATCH] Side
85 +Subject: [PATCH 3/3] Side
86
87 ---
88 dir/sub | 2 ++
t/t4013/diff.format-patch_--stdout_initial..master^
+2 -2
@@ -2,7 +2,7 @@ $ git format-patch --stdout initial..master^
2 From 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44 Mon Sep 17 00:00:00 2001
3 From: A U Thor <author@example.com>
4 Date: Mon, 26 Jun 2006 00:01:00 +0000
5 -Subject: [PATCH] Second
5 +Subject: [PATCH 1/2] Second
6
7 This is the second commit.
8 ---
@@ -48,7 +48,7 @@ g-i-t--v-e-r-s-i-o-n
48 From 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 Mon Sep 17 00:00:00 2001
49 From: A U Thor <author@example.com>
50 Date: Mon, 26 Jun 2006 00:02:00 +0000
51 -Subject: [PATCH] Third
51 +Subject: [PATCH 2/2] Third
52
53 ---
54 dir/sub | 2 ++
t/t4021-format-patch-numbered.sh
+10 -5
@@ -45,17 +45,22 @@ test_numbered() {
45 grep "^Subject: \[PATCH 2/2\]" $1
46 }
47
48 -test_expect_success 'Default: no numbered' '
48 +test_expect_success 'single patch defaults to no numbers' '
49 + git format-patch --stdout HEAD~1 >patch0.single &&
50 + test_single_no_numbered patch0.single
51 +'
52 +
53 +test_expect_success 'multiple patch defaults to numbered' '
54
50 - git format-patch --stdout HEAD~2 >patch0 &&
51 - test_no_numbered patch0
55 + git format-patch --stdout HEAD~2 >patch0.multiple &&
56 + test_numbered patch0.multiple
57
58 '
59
60 test_expect_success 'Use --numbered' '
61
57 - git format-patch --numbered --stdout HEAD~2 >patch1 &&
58 - test_numbered patch1
62 + git format-patch --numbered --stdout HEAD~1 >patch1 &&
63 + test_single_numbered patch1
64
65 '
66
t/t4151-am-abort.sh
+1 -1
@@ -22,7 +22,7 @@ test_expect_success setup '
22 test_tick &&
23 git commit -a -m $i || break
24 done &&
25 - git format-patch initial &&
25 + git format-patch --no-numbered initial &&
26 git checkout -b side initial &&
27 echo local change >file-2-expect
28 '