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>maint
parent
ec563e8153
commit
e6ff0f42bb
|
@ -11,7 +11,8 @@ SYNOPSIS
|
||||||
[verse]
|
[verse]
|
||||||
'git-format-patch' [-n | -k] [-o <dir> | --stdout] [--thread]
|
'git-format-patch' [-n | -k] [-o <dir> | --stdout] [--thread]
|
||||||
[--attach[=<boundary>] | --inline[=<boundary>]]
|
[--attach[=<boundary>] | --inline[=<boundary>]]
|
||||||
[-s | --signoff] [<common diff options>] [--start-number <n>]
|
[-s | --signoff] [<common diff options>]
|
||||||
|
[--start-number <n>] [--numbered-files]
|
||||||
[--in-reply-to=Message-Id] [--suffix=.<sfx>]
|
[--in-reply-to=Message-Id] [--suffix=.<sfx>]
|
||||||
[--ignore-if-in-upstream]
|
[--ignore-if-in-upstream]
|
||||||
[--subject-prefix=Subject-Prefix]
|
[--subject-prefix=Subject-Prefix]
|
||||||
|
@ -30,9 +31,11 @@ gitlink:git-rev-parse[1].
|
||||||
The output of this command is convenient for e-mail submission or
|
The output of this command is convenient for e-mail submission or
|
||||||
for use with gitlink:git-am[1].
|
for use with gitlink:git-am[1].
|
||||||
|
|
||||||
Each output file is numbered sequentially from 1, and uses the
|
By default, each output file is numbered sequentially from 1, and uses the
|
||||||
first line of the commit message (massaged for pathname safety) as
|
first line of the commit message (massaged for pathname safety) as
|
||||||
the filename. The names of the output files are printed to standard
|
the filename. With the --numbered-files option, the output file names
|
||||||
|
will only be numbers, without the first line of the commit appended.
|
||||||
|
The names of the output files are printed to standard
|
||||||
output, unless the --stdout option is specified.
|
output, unless the --stdout option is specified.
|
||||||
|
|
||||||
If -o is specified, output files are created in <dir>. Otherwise
|
If -o is specified, output files are created in <dir>. Otherwise
|
||||||
|
@ -60,6 +63,11 @@ include::diff-options.txt[]
|
||||||
--start-number <n>::
|
--start-number <n>::
|
||||||
Start numbering the patches at <n> instead of 1.
|
Start numbering the patches at <n> instead of 1.
|
||||||
|
|
||||||
|
--numbered-files::
|
||||||
|
Output file names will be a simple number sequence
|
||||||
|
without the default first line of the commit appended.
|
||||||
|
Mutually exclusive with the --stdout option.
|
||||||
|
|
||||||
-k|--keep-subject::
|
-k|--keep-subject::
|
||||||
Do not strip/add '[PATCH]' from the first line of the
|
Do not strip/add '[PATCH]' from the first line of the
|
||||||
commit log message.
|
commit log message.
|
||||||
|
|
|
@ -298,7 +298,8 @@ static int git_format_config(const char *var, const char *value)
|
||||||
static FILE *realstdout = NULL;
|
static FILE *realstdout = NULL;
|
||||||
static const char *output_directory = NULL;
|
static const char *output_directory = NULL;
|
||||||
|
|
||||||
static int reopen_stdout(struct commit *commit, int nr, int keep_subject)
|
static int reopen_stdout(struct commit *commit, int nr, int keep_subject,
|
||||||
|
int numbered_files)
|
||||||
{
|
{
|
||||||
char filename[PATH_MAX];
|
char filename[PATH_MAX];
|
||||||
char *sol;
|
char *sol;
|
||||||
|
@ -315,6 +316,11 @@ static int reopen_stdout(struct commit *commit, int nr, int keep_subject)
|
||||||
filename[len++] = '/';
|
filename[len++] = '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (numbered_files) {
|
||||||
|
sprintf(filename + len, "%d", nr);
|
||||||
|
len = strlen(filename);
|
||||||
|
|
||||||
|
} else {
|
||||||
sprintf(filename + len, "%04d", nr);
|
sprintf(filename + len, "%04d", nr);
|
||||||
len = strlen(filename);
|
len = strlen(filename);
|
||||||
|
|
||||||
|
@ -350,18 +356,21 @@ static int reopen_stdout(struct commit *commit, int nr, int keep_subject)
|
||||||
} else
|
} else
|
||||||
space = 1;
|
space = 1;
|
||||||
}
|
}
|
||||||
while (filename[len - 1] == '.' || filename[len - 1] == '-')
|
while (filename[len - 1] == '.'
|
||||||
|
|| filename[len - 1] == '-')
|
||||||
len--;
|
len--;
|
||||||
filename[len] = 0;
|
filename[len] = 0;
|
||||||
}
|
}
|
||||||
if (len + suffix_len >= sizeof(filename))
|
if (len + suffix_len >= sizeof(filename))
|
||||||
return error("Patch pathname too long");
|
return error("Patch pathname too long");
|
||||||
strcpy(filename + len, fmt_patch_suffix);
|
strcpy(filename + len, fmt_patch_suffix);
|
||||||
|
}
|
||||||
|
|
||||||
fprintf(realstdout, "%s\n", filename);
|
fprintf(realstdout, "%s\n", filename);
|
||||||
if (freopen(filename, "w", stdout) == NULL)
|
if (freopen(filename, "w", stdout) == NULL)
|
||||||
return error("Cannot open patch file %s",filename);
|
return error("Cannot open patch file %s",filename);
|
||||||
return 0;
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids, const char *prefix)
|
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)
|
||||||
int numbered = 0;
|
int numbered = 0;
|
||||||
int start_number = -1;
|
int start_number = -1;
|
||||||
int keep_subject = 0;
|
int keep_subject = 0;
|
||||||
|
int numbered_files = 0; /* _just_ numbers */
|
||||||
int subject_prefix = 0;
|
int subject_prefix = 0;
|
||||||
int ignore_if_in_upstream = 0;
|
int ignore_if_in_upstream = 0;
|
||||||
int thread = 0;
|
int thread = 0;
|
||||||
|
@ -465,6 +475,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
|
||||||
numbered = 1;
|
numbered = 1;
|
||||||
else if (!prefixcmp(argv[i], "--start-number="))
|
else if (!prefixcmp(argv[i], "--start-number="))
|
||||||
start_number = strtol(argv[i] + 15, NULL, 10);
|
start_number = strtol(argv[i] + 15, NULL, 10);
|
||||||
|
else if (!strcmp(argv[i], "--numbered-files"))
|
||||||
|
numbered_files = 1;
|
||||||
else if (!strcmp(argv[i], "--start-number")) {
|
else if (!strcmp(argv[i], "--start-number")) {
|
||||||
i++;
|
i++;
|
||||||
if (i == argc)
|
if (i == argc)
|
||||||
|
@ -540,6 +552,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
|
||||||
die ("-n and -k are mutually exclusive.");
|
die ("-n and -k are mutually exclusive.");
|
||||||
if (keep_subject && subject_prefix)
|
if (keep_subject && subject_prefix)
|
||||||
die ("--subject-prefix and -k are mutually exclusive.");
|
die ("--subject-prefix and -k are mutually exclusive.");
|
||||||
|
if (numbered_files && use_stdout)
|
||||||
|
die ("--numbered-files and --stdout are mutually exclusive.");
|
||||||
|
|
||||||
argc = setup_revisions(argc, argv, &rev, "HEAD");
|
argc = setup_revisions(argc, argv, &rev, "HEAD");
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
|
@ -614,7 +628,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
|
||||||
rev.message_id = message_id;
|
rev.message_id = message_id;
|
||||||
}
|
}
|
||||||
if (!use_stdout)
|
if (!use_stdout)
|
||||||
if (reopen_stdout(commit, rev.nr, keep_subject))
|
if (reopen_stdout(commit, rev.nr, keep_subject,
|
||||||
|
numbered_files))
|
||||||
die("Failed to create output files");
|
die("Failed to create output files");
|
||||||
shown = log_tree_commit(&rev, commit);
|
shown = log_tree_commit(&rev, commit);
|
||||||
free(commit->buffer);
|
free(commit->buffer);
|
||||||
|
|
Loading…
Reference in New Issue