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

[PATCH v2] http: use internal argv_array of struct child_process

From
René Scharfe <l.s.r@web.de>
Date
Dec 22, 2017, 11:56 UTC
Message-ID
<6bebb8a0-31ec-b20c-2430-2d69daa63dea@web.de>
In-Reply-To
<CAPig+cQaQ9ae1e4eMfJMG4wykXe2tTgtvpxB1_Z=3XbitYeQyw@mail.gmail.com>

Avoid a strangely magic array size (it's slightly too big) and explicit index numbers by building the command line for index-pack using the embedded argv_array of the child_process. Add the flag -o and its argument with argv_array_pushl() to make it obvious that they belong together. The resulting code is shorter and easier to extend.

Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
Change from v1: use argv_array_pushl for -o and tmp_idx.
Thanks, Eric, good idea!
 http.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/http.c b/http.c
index 215bebef1b..9f2fcc9ec4 100644
--- a/http.c
+++ b/http.c
@@ -2025,7 +2025,6 @@ int finish_http_pack_request(struct http_pack_request *preq)
 	char *tmp_idx;
 	size_t len;
 	struct child_process ip = CHILD_PROCESS_INIT;
-	const char *ip_argv[8];
 
 	close_pack_index(p);
 
@@ -2041,13 +2040,9 @@ int finish_http_pack_request(struct http_pack_request *preq)
 		die("BUG: pack tmpfile does not end in .pack.temp?");
 	tmp_idx = xstrfmt("%.*s.idx.temp", (int)len, preq->tmpfile);
 
-	ip_argv[0] = "index-pack";
-	ip_argv[1] = "-o";
-	ip_argv[2] = tmp_idx;
-	ip_argv[3] = preq->tmpfile;
-	ip_argv[4] = NULL;
-
-	ip.argv = ip_argv;
+	argv_array_push(&ip.args, "index-pack");
+	argv_array_pushl(&ip.args, "-o", tmp_idx, NULL);
+	argv_array_push(&ip.args, preq->tmpfile);
 	ip.git_cmd = 1;
 	ip.no_stdin = 1;
 	ip.no_stdout = 1;
-- 
2.15.1
Previous: Eric Sunshine
Message 3 of 3 in “http: use internal argv_array of struct child_process”
  1. http: use internal argv_array of struct child_processRené Scharfe, Dec 22, 2017
  2. Eric SunshineDec 22, 2017
  3. http: use internal argv_array of struct child_processRené Scharfe, Dec 22, 2017

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.