Add the --numbered-files option to git-format-patch.
With this option, git-format-patch will generate simple numbered files as output instead of the default using with the first commit line appended. This simplifies the ability to generate an MH-style drafts folder with each message to be sent. Signed-off-by: Jon Loeliger <jdl@freescale.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jon Loeliger committed
Jun 5, 2007 at 15:06 UTC
e6ff0f42bb0c63515c8489c1992f37d1d1e8b2f4
2 files changed
+67
-44
Documentation/git-format-patch.txt
+11
-3
@@ -11,7 +11,8 @@ SYNOPSIS
11
[verse]
12
'git-format-patch' [-n | -k] [-o <dir> | --stdout] [--thread]
13
[--attach[=<boundary>] | --inline[=<boundary>]]
14
- [-s | --signoff] [<common diff options>] [--start-number <n>]
14
+ [-s | --signoff] [<common diff options>]
15
+ [--start-number <n>] [--numbered-files]
16
[--in-reply-to=Message-Id] [--suffix=.<sfx>]
17
[--ignore-if-in-upstream]
18
[--subject-prefix=Subject-Prefix]
@@ -30,9 +31,11 @@ gitlink:git-rev-parse[1].
31
The output of this command is convenient for e-mail submission or
32
for use with gitlink:git-am[1].
33
33
-Each output file is numbered sequentially from 1, and uses the
34
+By default, each output file is numbered sequentially from 1, and uses the
35
first line of the commit message (massaged for pathname safety) as
35
-the filename. The names of the output files are printed to standard
36
+the filename. With the --numbered-files option, the output file names
37
+will only be numbers, without the first line of the commit appended.
38
+The names of the output files are printed to standard
39
output, unless the --stdout option is specified.
40
41
If -o is specified, output files are created in <dir>. Otherwise
@@ -60,6 +63,11 @@ include::diff-options.txt[]
63
--start-number <n>::
64
Start numbering the patches at <n> instead of 1.
65
66
+--numbered-files::
67
+ Output file names will be a simple number sequence
68
+ without the default first line of the commit appended.
69
+ Mutually exclusive with the --stdout option.
70
+
71
-k|--keep-subject::
72
Do not strip/add '[PATCH]' from the first line of the
73
commit log message.
builtin-log.c
+56
-41
@@ -298,7 +298,8 @@ static int git_format_config(const char *var, const char *value)
298
static FILE *realstdout = NULL;
299
static const char *output_directory = NULL;
300
301
-static int reopen_stdout(struct commit *commit, int nr, int keep_subject)
301
+static int reopen_stdout(struct commit *commit, int nr, int keep_subject,
302
+ int numbered_files)
303
{
304
char filename[PATH_MAX];
305
char *sol;
@@ -315,53 +316,61 @@ static int reopen_stdout(struct commit *commit, int nr, int keep_subject)
316
filename[len++] = '/';
317
}
318
318
- sprintf(filename + len, "%04d", nr);
319
- len = strlen(filename);
320
-
321
- sol = strstr(commit->buffer, "\n\n");
322
- if (sol) {
323
- int j, space = 1;
324
-
325
- sol += 2;
326
- /* strip [PATCH] or [PATCH blabla] */
327
- if (!keep_subject && !prefixcmp(sol, "[PATCH")) {
328
- char *eos = strchr(sol + 6, ']');
329
- if (eos) {
330
- while (isspace(*eos))
331
- eos++;
332
- sol = eos;
333
- }
334
- }
319
+ if (numbered_files) {
320
+ sprintf(filename + len, "%d", nr);
321
+ len = strlen(filename);
322
336
- for (j = 0;
337
- j < FORMAT_PATCH_NAME_MAX - suffix_len - 5 &&
338
- len < sizeof(filename) - suffix_len &&
339
- sol[j] && sol[j] != '\n';
340
- j++) {
341
- if (istitlechar(sol[j])) {
342
- if (space) {
343
- filename[len++] = '-';
344
- space = 0;
323
+ } else {
324
+ sprintf(filename + len, "%04d", nr);
325
+ len = strlen(filename);
326
+
327
+ sol = strstr(commit->buffer, "\n\n");
328
+ if (sol) {
329
+ int j, space = 1;
330
+
331
+ sol += 2;
332
+ /* strip [PATCH] or [PATCH blabla] */
333
+ if (!keep_subject && !prefixcmp(sol, "[PATCH")) {
334
+ char *eos = strchr(sol + 6, ']');
335
+ if (eos) {
336
+ while (isspace(*eos))
337
+ eos++;
338
+ sol = eos;
339
}
346
- filename[len++] = sol[j];
347
- if (sol[j] == '.')
348
- while (sol[j + 1] == '.')
349
- j++;
350
- } else
351
- space = 1;
340
+ }
341
+
342
+ for (j = 0;
343
+ j < FORMAT_PATCH_NAME_MAX - suffix_len - 5 &&
344
+ len < sizeof(filename) - suffix_len &&
345
+ sol[j] && sol[j] != '\n';
346
+ j++) {
347
+ if (istitlechar(sol[j])) {
348
+ if (space) {
349
+ filename[len++] = '-';
350
+ space = 0;
351
+ }
352
+ filename[len++] = sol[j];
353
+ if (sol[j] == '.')
354
+ while (sol[j + 1] == '.')
355
+ j++;
356
+ } else
357
+ space = 1;
358
+ }
359
+ while (filename[len - 1] == '.'
360
+ || filename[len - 1] == '-')
361
+ len--;
362
+ filename[len] = 0;
363
}
353
- while (filename[len - 1] == '.' || filename[len - 1] == '-')
354
- len--;
355
- filename[len] = 0;
364
+ if (len + suffix_len >= sizeof(filename))
365
+ return error("Patch pathname too long");
366
+ strcpy(filename + len, fmt_patch_suffix);
367
}
357
- if (len + suffix_len >= sizeof(filename))
358
- return error("Patch pathname too long");
359
- strcpy(filename + len, fmt_patch_suffix);
368
+
369
fprintf(realstdout, "%s\n", filename);
370
if (freopen(filename, "w", stdout) == NULL)
371
return error("Cannot open patch file %s",filename);
363
- return 0;
372
373
+ return 0;
374
}
375
376
static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids, const char *prefix)
@@ -431,6 +440,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
440
int numbered = 0;
441
int start_number = -1;
442
int keep_subject = 0;
443
+ int numbered_files = 0; /* _just_ numbers */
444
int subject_prefix = 0;
445
int ignore_if_in_upstream = 0;
446
int thread = 0;
@@ -465,6 +475,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
475
numbered = 1;
476
else if (!prefixcmp(argv[i], "--start-number="))
477
start_number = strtol(argv[i] + 15, NULL, 10);
478
+ else if (!strcmp(argv[i], "--numbered-files"))
479
+ numbered_files = 1;
480
else if (!strcmp(argv[i], "--start-number")) {
481
i++;
482
if (i == argc)
@@ -540,6 +552,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
552
die ("-n and -k are mutually exclusive.");
553
if (keep_subject && subject_prefix)
554
die ("--subject-prefix and -k are mutually exclusive.");
555
+ if (numbered_files && use_stdout)
556
+ die ("--numbered-files and --stdout are mutually exclusive.");
557
558
argc = setup_revisions(argc, argv, &rev, "HEAD");
559
if (argc > 1)
@@ -614,7 +628,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
628
rev.message_id = message_id;
629
}
630
if (!use_stdout)
617
- if (reopen_stdout(commit, rev.nr, keep_subject))
631
+ if (reopen_stdout(commit, rev.nr, keep_subject,
632
+ numbered_files))
633
die("Failed to create output files");
634
shown = log_tree_commit(&rev, commit);
635
free(commit->buffer);