http: use internal argv_array of struct child_process

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Dec 22, 2017 at 12:56 UTC c7191fa51011f9ae03686269a16ce0c03e97afec
1 file changed +3 -8
http.c
+3 -8
@@ -2025,7 +2025,6 @@ int finish_http_pack_request(struct http_pack_request *preq)
2025 char *tmp_idx;
2026 size_t len;
2027 struct child_process ip = CHILD_PROCESS_INIT;
2028 - const char *ip_argv[8];
2028
2029 close_pack_index(p);
2030
@@ -2041,13 +2040,9 @@ int finish_http_pack_request(struct http_pack_request *preq)
2040 die("BUG: pack tmpfile does not end in .pack.temp?");
2041 tmp_idx = xstrfmt("%.*s.idx.temp", (int)len, preq->tmpfile);
2042
2044 - ip_argv[0] = "index-pack";
2045 - ip_argv[1] = "-o";
2046 - ip_argv[2] = tmp_idx;
2047 - ip_argv[3] = preq->tmpfile;
2048 - ip_argv[4] = NULL;
2049 -
2050 - ip.argv = ip_argv;
2043 + argv_array_push(&ip.args, "index-pack");
2044 + argv_array_pushl(&ip.args, "-o", tmp_idx, NULL);
2045 + argv_array_push(&ip.args, preq->tmpfile);
2046 ip.git_cmd = 1;
2047 ip.no_stdin = 1;
2048 ip.no_stdout = 1;