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

[PATCH] builtin-archive: insert --format before double dash if necessary.

From
Miklos Vajna <vmiklos@frugalware.org>
Date
Dec 10, 2009, 22:20 UTC
Message-ID
<20091210222005.GP4114@genesis.frugalware.org>
In-Reply-To
<20091210212636.GA27722@Knoppix>
Reported-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
---
What about this fix?
 builtin-archive.c |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)
diff --git a/builtin-archive.c b/builtin-archive.c
index 12351e9..ffbc9b0 100644
--- a/builtin-archive.c
+++ b/builtin-archive.c
@@ -104,14 +104,35 @@ int cmd_archive(int argc, const char **argv, const char *prefix)
 	}
 
 	if (format) {
+		int i, found = 0;
+		const char *ptr = NULL;
+
 		sprintf(fmt_opt, "--format=%s", format);
 		/*
 		 * This is safe because either --format and/or --output must
 		 * have been given on the original command line if we get to
 		 * this point, and parse_options() must have eaten at least
 		 * one argument, i.e. we have enough room to append to argv[].
+		 *
+		 * First check if we have to insert the argument before
+		 * two dashes.
 		 */
-		argv[argc++] = fmt_opt;
+		for (i = 0; i < argc; i++) {
+			if (found) {
+				const char *tmp = argv[i];
+				argv[i] = ptr;
+				ptr = tmp;
+			} else if (!strcmp(argv[i], "--")) {
+				found = 1;
+				ptr = argv[i];
+				argv[i] = fmt_opt;
+				argc++;
+			}
+		}
+
+		/* No double dash? Then just append it to the end of the list. */
+		if (!found)
+			argv[argc++] = fmt_opt;
 		argv[argc] = NULL;
 	}
 
-- 
1.6.5.2
Previous: Ilari Liusvaara
Message 11 of 11 in “[BUG] git archive formats and dashdash”
  1. Ilari LiusvaaraDec 10, 2009
  2. Junio C HamanoDec 10, 2009
  3. Miklos VajnaDec 10, 2009
  4. Junio C HamanoDec 10, 2009
  5. Fix archive format with -- on the command lineJunio C Hamano, Dec 10, 2009
  6. Junio C HamanoDec 10, 2009
  7. René ScharfeDec 12, 2009
  8. Nanako ShiraishiDec 30, 2009
  9. Junio C HamanoDec 30, 2009
  10. Ilari LiusvaaraDec 10, 2009
  11. builtin-archive: insert --format before double dash if necessary.Miklos Vajna, Dec 10, 2009

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.