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

[PATCH 3/4] replace: use argv_array in export_object

From
Jeff King <peff@peff.net>
Date
Jun 24, 2014, 09:46 UTC
Message-ID
<20140624094605.GC14514@sigill.intra.peff.net>
In-Reply-To
<20140624094217.GA14216@sigill.intra.peff.net>

This is a little more verbose, but will make it easier to make parts of our command-line conditional (without resorting to magic numbers or lots of NULLs to get an appropriately sized argv array).

Signed-off-by: Jeff King <peff@peff.net>
---
 builtin/replace.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/builtin/replace.c b/builtin/replace.c
index eb1d2ec..2584170 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -193,15 +193,17 @@ static int replace_object(const char *object_ref, const char *replace_ref, int f
  */
 static void export_object(const unsigned char *sha1, const char *filename)
 {
-	const char *argv[] = { "--no-replace-objects", "cat-file", "-p", NULL, NULL };
-	struct child_process cmd = { argv };
+	struct child_process cmd = { NULL };
 	int fd;
 
 	fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
 	if (fd < 0)
 		die_errno("unable to open %s for writing", filename);
 
-	argv[3] = sha1_to_hex(sha1);
+	argv_array_push(&cmd.args, "--no-replace-objects");
+	argv_array_push(&cmd.args, "cat-file");
+	argv_array_push(&cmd.args, "-p");
+	argv_array_push(&cmd.args, sha1_to_hex(sha1));
 	cmd.git_cmd = 1;
 	cmd.out = fd;
 
-- 
2.0.0.566.gfe3e6b2
Previous: Jeff KingNext: Jeff King
Message 4 of 9 in “git replace --edit --raw”
  1. 0/4 git replace --edit --rawJeff King, Jun 24, 2014
  2. 1/4 replace: replace spaces with tabs in indentationJeff King, Jun 24, 2014
  3. 2/4 avoid double close of descriptors handed to run_commandJeff King, Jun 24, 2014
  4. 3/4 replace: use argv_array in export_objectJeff King, Jun 24, 2014
  5. 4/4 replace: add a --raw mode for --editJeff King, Jun 24, 2014
  6. Eric SunshineJun 25, 2014
  7. Jeff KingJun 25, 2014
  8. Junio C HamanoJun 25, 2014
  9. Jeff KingJun 26, 2014

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.