Skip to content

Commit 49604a4

Browse files
Benabikgitster
authored andcommitted
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. Signed-off-by: Brian Gernhardt <benji@silverinsanity.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 140dd77 commit 49604a4

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

Documentation/config.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,12 @@ fetch.unpackLimit::
432432
pack from a push can make the push operation complete faster,
433433
especially on slow filesystems.
434434

435+
format.numbered::
436+
A boolean which can enable sequence numbers in patch subjects.
437+
Seting this option to "auto" will enable it only if there is
438+
more than one patch. See --numbered option in
439+
gitlink:git-format-patch[1].
440+
435441
format.headers::
436442
Additional email headers to include in a patch to be submitted
437443
by mail. See gitlink:git-format-patch[1].

Documentation/git-format-patch.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ git-format-patch - Prepare patches for e-mail submission
99
SYNOPSIS
1010
--------
1111
[verse]
12-
'git-format-patch' [-n | -k] [-o <dir> | --stdout] [--thread]
12+
'git-format-patch' [-n | -N | -k] [-o <dir> | --stdout] [--thread]
1313
[--attach[=<boundary>] | --inline[=<boundary>]]
1414
[-s | --signoff] [<common diff options>]
1515
[--start-number <n>] [--numbered-files]
@@ -77,6 +77,9 @@ include::diff-options.txt[]
7777
-n|--numbered::
7878
Name output in '[PATCH n/m]' format.
7979

80+
-N|--no-numbered::
81+
Name output in '[PATCH]' format.
82+
8083
--start-number <n>::
8184
Start numbering the patches at <n> instead of 1.
8285

@@ -142,15 +145,16 @@ not add any suffix.
142145

143146
CONFIGURATION
144147
-------------
145-
You can specify extra mail header lines to be added to each
146-
message in the repository configuration. You can also specify
147-
new defaults for the subject prefix and file suffix.
148+
You can specify extra mail header lines to be added to each message
149+
in the repository configuration, new defaults for the subject prefix
150+
and file suffix, and number patches when outputting more than one.
148151

149152
------------
150153
[format]
151154
headers = "Organization: git-foo\n"
152155
subjectprefix = CHANGE
153156
suffix = .txt
157+
numbered = auto
154158
------------
155159

156160

builtin-log.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ static int istitlechar(char c)
273273
static char *extra_headers = NULL;
274274
static int extra_headers_size = 0;
275275
static const char *fmt_patch_suffix = ".patch";
276+
static int numbered = 0;
277+
static int auto_number = 0;
276278

277279
static int git_format_config(const char *var, const char *value)
278280
{
@@ -297,6 +299,15 @@ static int git_format_config(const char *var, const char *value)
297299
if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {
298300
return 0;
299301
}
302+
if (!strcmp(var, "format.numbered")) {
303+
if (!strcasecmp(value, "auto")) {
304+
auto_number = 1;
305+
return 0;
306+
}
307+
308+
numbered = git_config_bool(var, value);
309+
return 0;
310+
}
300311

301312
return git_log_config(var, value);
302313
}
@@ -466,7 +477,6 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
466477
struct rev_info rev;
467478
int nr = 0, total, i, j;
468479
int use_stdout = 0;
469-
int numbered = 0;
470480
int start_number = -1;
471481
int keep_subject = 0;
472482
int numbered_files = 0; /* _just_ numbers */
@@ -503,6 +513,11 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
503513
else if (!strcmp(argv[i], "-n") ||
504514
!strcmp(argv[i], "--numbered"))
505515
numbered = 1;
516+
else if (!strcmp(argv[i], "-N") ||
517+
!strcmp(argv[i], "--no-numbered")) {
518+
numbered = 0;
519+
auto_number = 0;
520+
}
506521
else if (!prefixcmp(argv[i], "--start-number="))
507522
start_number = strtol(argv[i] + 15, NULL, 10);
508523
else if (!strcmp(argv[i], "--numbered-files"))
@@ -642,6 +657,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
642657
list[nr - 1] = commit;
643658
}
644659
total = nr;
660+
if (!keep_subject && auto_number && total > 1)
661+
numbered = 1;
645662
if (numbered)
646663
rev.total = total + start_number - 1;
647664
rev.add_signoff = add_signoff;

0 commit comments

Comments
 (0)