@matheusbsbs / matheus-bagliano / commits / 03eeaeaea5
Fork 0

Introduce 'git-format-patch --suffix=.patch'

The default can also be changed with "format.suffix" configuration. Leaving it empty would not add any suffix. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Jan 17, 2007 at 11:12 UTC 03eeaeaea57485e288dfecc37b120b074d6e92de
2 files changed +32 -4
Documentation/git-format-patch.txt
+16 -1
@@ -11,7 +11,7 @@ SYNOPSIS
11 [verse]
12 'git-format-patch' [-n | -k] [-o <dir> | --stdout] [--attach] [--thread]
13 [-s | --signoff] [--diff-options] [--start-number <n>]
14 - [--in-reply-to=Message-Id]
14 + [--in-reply-to=Message-Id] [--suffix=.<sfx>]
15 <since>[..<until>]
16
17 DESCRIPTION
@@ -78,6 +78,16 @@ OPTIONS
78 reply to the given Message-Id, which avoids breaking threads to
79 provide a new patch series.
80
81 +--suffix=.<sfx>::
82 + Instead of using `.txt` as the suffix for generated
83 + filenames, use specifed suffix. A common alternative is
84 + `--suffix=.patch`.
85 ++
86 +Note that you would need to include the leading dot `.` if you
87 +want a filename like `0001-description-of-my-change.patch`, and
88 +the first letter does not have to be a dot. Leaving it empty would
89 +not add any suffix.
90 +
91 CONFIGURATION
92 -------------
93 You can specify extra mail header lines to be added to each
@@ -86,6 +96,11 @@ message in the repository configuration as follows:
96 [format]
97 headers = "Organization: git-foo\n"
98
99 +You can specify default suffix used:
100 +
101 +[format]
102 + suffix = .patch
103 +
104
105 EXAMPLES
106 --------
builtin-log.c
+16 -3
@@ -197,6 +197,7 @@ static int istitlechar(char c)
197
198 static char *extra_headers = NULL;
199 static int extra_headers_size = 0;
200 +static const char *fmt_patch_suffix = ".txt";
201
202 static int git_format_config(const char *var, const char *value)
203 {
@@ -208,6 +209,12 @@ static int git_format_config(const char *var, const char *value)
209 strcat(extra_headers, value);
210 return 0;
211 }
212 + if (!strcmp(var, "format.suffix")) {
213 + if (!value)
214 + die("format.suffix without value");
215 + fmt_patch_suffix = xstrdup(value);
216 + return 0;
217 + }
218 if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {
219 return 0;
220 }
@@ -223,9 +230,10 @@ static void reopen_stdout(struct commit *commit, int nr, int keep_subject)
230 char filename[1024];
231 char *sol;
232 int len = 0;
233 + int suffix_len = strlen(fmt_patch_suffix) + 10; /* ., NUL and slop */
234
235 if (output_directory) {
228 - strlcpy(filename, output_directory, 1010);
236 + strlcpy(filename, output_directory, 1000);
237 len = strlen(filename);
238 if (filename[len - 1] != '/')
239 filename[len++] = '/';
@@ -249,7 +257,10 @@ static void reopen_stdout(struct commit *commit, int nr, int keep_subject)
257 }
258 }
259
252 - for (j = 0; len < 1024 - 6 && sol[j] && sol[j] != '\n'; j++) {
260 + for (j = 0;
261 + len < sizeof(filename) - suffix_len &&
262 + sol[j] && sol[j] != '\n';
263 + j++) {
264 if (istitlechar(sol[j])) {
265 if (space) {
266 filename[len++] = '-';
@@ -265,7 +276,7 @@ static void reopen_stdout(struct commit *commit, int nr, int keep_subject)
276 while (filename[len - 1] == '.' || filename[len - 1] == '-')
277 len--;
278 }
268 - strcpy(filename + len, ".txt");
279 + strcpy(filename + len, fmt_patch_suffix);
280 fprintf(realstdout, "%s\n", filename);
281 freopen(filename, "w", stdout);
282 }
@@ -436,6 +447,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
447 die("Need a Message-Id for --in-reply-to");
448 in_reply_to = argv[i];
449 }
450 + else if (!strncmp(argv[i], "--suffix=", 9))
451 + fmt_patch_suffix = argv[i] + 9;
452 else
453 argv[j++] = argv[i];
454 }