git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] git-format-patch: add --output-directory long option again

From
Junio C Hamano <junkio@cox.net>
Date
Jun 6, 2006, 15:46 UTC
Message-ID
<7vwtbuthgw.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<20060606141946.G59b8a1fd@leonov.stosberg.net>
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.
Show 6 quoted lines
> +	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
Previous: Johannes SchindelinNext: Dennis Stosberg
Message 3 of 4 in “git-format-patch: add --output-directory long option again”
  1. git-format-patch: add --output-directory long option againDennis Stosberg, Jun 6, 2006
  2. Johannes SchindelinJun 6, 2006
  3. Junio C HamanoJun 6, 2006
  4. Dennis StosbergJun 6, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.