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

git-format-patch: add --output-directory long option again

Additionally notices and complains to an -o option without directory or a duplicated -o option, -o and --stdout given together. Also delays the creation of directory until all arguments are parsed, so that the command does not leave an empty directory behind when it exits after seeing an unrelated invalid option. [jc: originally from Dennis Stosberg but with minor fixes, and documentation updates from Dennis.] Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Jun 6, 2006 at 08:46 UTC efd0201684c6e9bf663811dc849590b8fe27b8b2
2 files changed +17 -12
Documentation/git-format-patch.txt
+1 -2
@@ -40,8 +40,7 @@ OPTIONS
40 -------
41 -o|--output-directory <dir>::
42 Use <dir> to store the resulting files, instead of the
43 - current working directory. This option is ignored if
44 - --stdout is specified.
43 + current working directory.
44
45 -n|--numbered::
46 Name output in '[PATCH n/m]' format.
builtin-log.c
+16 -10
@@ -103,7 +103,7 @@ static int git_format_config(const char *var, const char *value)
103
104
105 static FILE *realstdout = NULL;
106 -static char *output_directory = NULL;
106 +static const char *output_directory = NULL;
107
108 static void reopen_stdout(struct commit *commit, int nr, int keep_subject)
109 {
@@ -206,14 +206,14 @@ int cmd_format_patch(int argc, const char **argv, char **envp)
206 keep_subject = 1;
207 rev.total = -1;
208 }
209 - else if (!strcmp(argv[i], "-o")) {
210 - if (argc < 3)
211 - die ("Which directory?");
212 - if (mkdir(argv[i + 1], 0777) < 0 && errno != EEXIST)
213 - die("Could not create directory %s",
214 - argv[i + 1]);
215 - output_directory = strdup(argv[i + 1]);
209 + else if (!strcmp(argv[i], "--output-directory") ||
210 + !strcmp(argv[i], "-o")) {
211 i++;
212 + if (argc <= i)
213 + die("Which directory?");
214 + if (output_directory)
215 + die("Two output directories?");
216 + output_directory = argv[i];
217 }
218 else if (!strcmp(argv[i], "--signoff") ||
219 !strcmp(argv[i], "-s")) {
@@ -243,6 +243,14 @@ int cmd_format_patch(int argc, const char **argv, char **envp)
243 if (argc > 1)
244 die ("unrecognized argument: %s", argv[1]);
245
246 + if (output_directory) {
247 + if (use_stdout)
248 + die("standard output, or directory, which one?");
249 + if (mkdir(output_directory, 0777) < 0 && errno != EEXIST)
250 + die("Could not create directory %s",
251 + output_directory);
252 + }
253 +
254 if (rev.pending_objects && rev.pending_objects->next == NULL) {
255 rev.pending_objects->item->flags |= UNINTERESTING;
256 add_head(&rev);
@@ -293,8 +301,6 @@ int cmd_format_patch(int argc, const char **argv, char **envp)
301 if (!use_stdout)
302 fclose(stdout);
303 }
296 - if (output_directory)
297 - free(output_directory);
304 free(list);
305 return 0;
306 }