* [PATCH] git-format-patch: add --output-directory long option again
@ 2006-06-06 14:19 Dennis Stosberg
2006-06-06 14:53 ` Johannes Schindelin
2006-06-06 15:46 ` Junio C Hamano
0 siblings, 2 replies; 4+ messages in thread
From: Dennis Stosberg @ 2006-06-06 14:19 UTC (permalink / raw)
To: git
Additionally this fixes two minor issues:
(1) git-format-patch left an empty directory behind if an invalid
option was given on the command line.
(2) mkdir() was called with a NULL argument (argv[argc]), if -o was
the last option on the command line.
Signed-off-by: Dennis Stosberg <dennis@stosberg.net>
---
builtin-log.c | 18 +++++++++++-------
1 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/builtin-log.c b/builtin-log.c
index 6612f4c..0018d13 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -206,14 +206,12 @@ int cmd_format_patch(int argc, const cha
keep_subject = 1;
rev.total = -1;
}
- else if (!strcmp(argv[i], "-o")) {
- if (argc < 3)
- die ("Which directory?");
- if (mkdir(argv[i + 1], 0777) < 0 && errno != EEXIST)
- die("Could not create directory %s",
- argv[i + 1]);
- output_directory = strdup(argv[i + 1]);
+ else if (!strcmp(argv[i], "-o") ||
+ !strcmp(argv[i], "--output-directory")) {
i++;
+ if (i == argc)
+ die ("Which directory?");
+ output_directory = strdup(argv[i]);
}
else if (!strcmp(argv[i], "--signoff") ||
!strcmp(argv[i], "-s")) {
@@ -243,6 +241,12 @@ int cmd_format_patch(int argc, const cha
if (argc > 1)
die ("unrecognized argument: %s", argv[1]);
+ if (output_directory && !stdout) {
+ if (mkdir(output_directory, 0777) < 0 && errno != EEXIST)
+ die("Could not create directory %s",
+ output_directory);
+ }
+
if (rev.pending_objects && rev.pending_objects->next == NULL) {
rev.pending_objects->item->flags |= UNINTERESTING;
add_head(&rev);
--
1.3.3+git20060602-dest0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] git-format-patch: add --output-directory long option again
2006-06-06 14:19 [PATCH] git-format-patch: add --output-directory long option again Dennis Stosberg
@ 2006-06-06 14:53 ` Johannes Schindelin
2006-06-06 15:46 ` Junio C Hamano
1 sibling, 0 replies; 4+ messages in thread
From: Johannes Schindelin @ 2006-06-06 14:53 UTC (permalink / raw)
To: Dennis Stosberg; +Cc: git
Hi,
what idiot wrote that part of the code originally? ;-)
On Tue, 6 Jun 2006, Dennis Stosberg wrote:
> @@ -243,6 +241,12 @@ int cmd_format_patch(int argc, const cha
> if (argc > 1)
> die ("unrecognized argument: %s", argv[1]);
>
> + if (output_directory && !stdout) {
> + if (mkdir(output_directory, 0777) < 0 && errno != EEXIST)
> + die("Could not create directory %s",
> + output_directory);
> + }
> +
> if (rev.pending_objects && rev.pending_objects->next == NULL) {
> rev.pending_objects->item->flags |= UNINTERESTING;
> add_head(&rev);
Would it not be better to
if (output_directory && stdout)
die("What do you want: stdout or a directory?");
Ciao,
Dscho
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] git-format-patch: add --output-directory long option again
2006-06-06 14:19 [PATCH] git-format-patch: add --output-directory long option again Dennis Stosberg
2006-06-06 14:53 ` Johannes Schindelin
@ 2006-06-06 15:46 ` Junio C Hamano
2006-06-06 18:22 ` Dennis Stosberg
1 sibling, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2006-06-06 15:46 UTC (permalink / raw)
To: Dennis Stosberg, Johannes Schindelin; +Cc: git
Dennis Stosberg <dennis@stosberg.net> writes:
> Additionally this fixes two minor issues:
Thanks.
> - else if (!strcmp(argv[i], "-o")) {
> - if (argc < 3)
> - die ("Which directory?");
Oops.
> + if (output_directory && !stdout) {
> + if (mkdir(output_directory, 0777) < 0 && errno != EEXIST)
> + die("Could not create directory %s",
> + output_directory);
> + }
> +
This code couldn't have been tested -- you meant to say
"use_stdout" here, not "stdout".
How about this instead?
-- >8 --
[PATCH] 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.
[Originally from Dennis Stosberg but with minor fixes.]
Signed-off-by: Junio C Hamano <junkio@cox.net>
---
builtin-log.c | 26 ++++++++++++++++----------
1 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/builtin-log.c b/builtin-log.c
index 6612f4c..29a8851 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -103,7 +103,7 @@ static int git_format_config(const char
static FILE *realstdout = NULL;
-static char *output_directory = NULL;
+static const char *output_directory = NULL;
static void reopen_stdout(struct commit *commit, int nr, int keep_subject)
{
@@ -206,14 +206,14 @@ int cmd_format_patch(int argc, const cha
keep_subject = 1;
rev.total = -1;
}
- else if (!strcmp(argv[i], "-o")) {
- if (argc < 3)
- die ("Which directory?");
- if (mkdir(argv[i + 1], 0777) < 0 && errno != EEXIST)
- die("Could not create directory %s",
- argv[i + 1]);
- output_directory = strdup(argv[i + 1]);
+ else if (!strcmp(argv[i], "--output-directory") ||
+ !strcmp(argv[i], "-o")) {
i++;
+ if (argc <= i)
+ die("Which directory?");
+ if (output_directory)
+ die("Two output directories?");
+ output_directory = argv[i];
}
else if (!strcmp(argv[i], "--signoff") ||
!strcmp(argv[i], "-s")) {
@@ -243,6 +243,14 @@ int cmd_format_patch(int argc, const cha
if (argc > 1)
die ("unrecognized argument: %s", argv[1]);
+ if (output_directory) {
+ if (use_stdout)
+ die("standard output, or directory, which one?");
+ if (mkdir(output_directory, 0777) < 0 && errno != EEXIST)
+ die("Could not create directory %s",
+ output_directory);
+ }
+
if (rev.pending_objects && rev.pending_objects->next == NULL) {
rev.pending_objects->item->flags |= UNINTERESTING;
add_head(&rev);
@@ -293,8 +301,6 @@ int cmd_format_patch(int argc, const cha
if (!use_stdout)
fclose(stdout);
}
- if (output_directory)
- free(output_directory);
free(list);
return 0;
}
--
1.4.0.rc1-dirty
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] git-format-patch: add --output-directory long option again
2006-06-06 15:46 ` Junio C Hamano
@ 2006-06-06 18:22 ` Dennis Stosberg
0 siblings, 0 replies; 4+ messages in thread
From: Dennis Stosberg @ 2006-06-06 18:22 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Johannes Schindelin, git
Junio C Hamano wrote:
> > + if (output_directory && !stdout) {
> > + if (mkdir(output_directory, 0777) < 0 && errno != EEXIST)
> > + die("Could not create directory %s",
> > + output_directory);
> > + }
> > +
>
> This code couldn't have been tested -- you meant to say
> "use_stdout" here, not "stdout".
Sorry. My version compiled and ran cleanly, but I was blinded by my
goal: I wanted the directory to be _not_ created and checked that,
but I didn't make sure, that the directory really existed in the
other case, since Git didn't produce an error.
> How about this instead?
> [...]
> + if (output_directory) {
> + if (use_stdout)
> + die("standard output, or directory, which one?");
Looks good. This piece changes behaviour; it no longer matches the
docs.
Regards,
Dennis
---
Documentation/git-format-patch.txt | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt
index 493cac2..4ca0014 100644
--- a/Documentation/git-format-patch.txt
+++ b/Documentation/git-format-patch.txt
@@ -40,8 +40,7 @@ OPTIONS
-------
-o|--output-directory <dir>::
Use <dir> to store the resulting files, instead of the
- current working directory. This option is ignored if
- --stdout is specified.
+ current working directory.
-n|--numbered::
Name output in '[PATCH n/m]' format.
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-06-06 18:22 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-06 14:19 [PATCH] git-format-patch: add --output-directory long option again Dennis Stosberg
2006-06-06 14:53 ` Johannes Schindelin
2006-06-06 15:46 ` Junio C Hamano
2006-06-06 18:22 ` Dennis Stosberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).