From c7191fa51011f9ae03686269a16ce0c03e97afec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Fri, 22 Dec 2017 12:56:59 +0100 Subject: [PATCH 1/2] 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 Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- 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; From a923e05944271e2aa887721a1d2f24bb418eeca7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Fri, 22 Dec 2017 09:14:10 +0100 Subject: [PATCH 2/2] send-pack: use internal argv_array of struct child_process Avoid a magic number of NULL placeholder values and a magic index by constructing the command line for pack-objects using the embedded argv_array of the child_process. The resulting code is shorter and easier to extend. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- send-pack.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/send-pack.c b/send-pack.c index a8cc6b266e..2112d3b27a 100644 --- a/send-pack.c +++ b/send-pack.c @@ -58,35 +58,25 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *extra, struc * the revision parameters to it via its stdin and * let its stdout go back to the other end. */ - const char *argv[] = { - "pack-objects", - "--all-progress-implied", - "--revs", - "--stdout", - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - }; struct child_process po = CHILD_PROCESS_INIT; FILE *po_in; int i; int rc; - i = 4; + argv_array_push(&po.args, "pack-objects"); + argv_array_push(&po.args, "--all-progress-implied"); + argv_array_push(&po.args, "--revs"); + argv_array_push(&po.args, "--stdout"); if (args->use_thin_pack) - argv[i++] = "--thin"; + argv_array_push(&po.args, "--thin"); if (args->use_ofs_delta) - argv[i++] = "--delta-base-offset"; + argv_array_push(&po.args, "--delta-base-offset"); if (args->quiet || !args->progress) - argv[i++] = "-q"; + argv_array_push(&po.args, "-q"); if (args->progress) - argv[i++] = "--progress"; + argv_array_push(&po.args, "--progress"); if (is_repository_shallow()) - argv[i++] = "--shallow"; - po.argv = argv; + argv_array_push(&po.args, "--shallow"); po.in = -1; po.out = args->stateless_rpc ? -1 : fd; po.git_cmd = 1;