run-command API users: use strvec_pushv(), not argv assignment

Migrate those run-command API users that assign directly to the "argv" member to use a strvec_pushv() of "args" instead. In these cases it did not make sense to further refactor these callers, e.g. daemon.c could be made to construct the arguments closer to handle(), but that would require moving the construction from its cmd_main() and pass "argv" through two intermediate functions. It would be possible for a change like this to introduce a regression if we were doing: cp.argv = argv; argv[1] = "foo"; And changed the code, as is being done here, to: strvec_pushv(&cp.args, argv); argv[1] = "foo"; But as viewing this change with the "-W" flag reveals none of these functions modify variable that's being pushed afterwards in a way that would introduce such a logic error. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Nov 25, 2021 at 23:52 UTC 6def0ff8785eb12ccc24ceebea04355e13ae24b6
7 files changed +10 -9
add-patch.c
+2 -2
@@ -413,7 +413,7 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
413 strvec_push(&args, ps->items[i].original);
414
415 setup_child_process(s, &cp, NULL);
416 - cp.argv = args.v;
416 + strvec_pushv(&cp.args, args.v);
417 res = capture_command(&cp, plain, 0);
418 if (res) {
419 strvec_clear(&args);
@@ -431,7 +431,7 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
431
432 setup_child_process(s, &colored_cp, NULL);
433 xsnprintf((char *)args.v[color_arg_index], 8, "--color");
434 - colored_cp.argv = args.v;
434 + strvec_pushv(&colored_cp.args, args.v);
435 colored = &s->colored;
436 res = capture_command(&colored_cp, colored, 0);
437 strvec_clear(&args);
daemon.c
+1 -1
@@ -922,7 +922,7 @@ static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen)
922 #endif
923 }
924
925 - cld.argv = cld_argv.v;
925 + strvec_pushv(&cld.args, cld_argv.v);
926 cld.in = incoming;
927 cld.out = dup(incoming);
928
http-backend.c
+1 -1
@@ -480,7 +480,7 @@ static void run_service(const char **argv, int buffer_input)
480 strvec_pushf(&cld.env_array,
481 "GIT_COMMITTER_EMAIL=%s@http.%s", user, host);
482
483 - cld.argv = argv;
483 + strvec_pushv(&cld.args, argv);
484 if (buffer_input || gzipped_request || req_len >= 0)
485 cld.in = -1;
486 cld.git_cmd = 1;
http.c
+3 -2
@@ -2126,8 +2126,9 @@ int finish_http_pack_request(struct http_pack_request *preq)
2126
2127 ip.git_cmd = 1;
2128 ip.in = tmpfile_fd;
2129 - ip.argv = preq->index_pack_args ? preq->index_pack_args
2130 - : default_index_pack_args;
2129 + strvec_pushv(&ip.args, preq->index_pack_args ?
2130 + preq->index_pack_args :
2131 + default_index_pack_args);
2132
2133 if (preq->preserve_index_pack_stdout)
2134 ip.out = 0;
remote-curl.c
+1 -1
@@ -1061,7 +1061,7 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads,
1061 client.in = -1;
1062 client.out = -1;
1063 client.git_cmd = 1;
1064 - client.argv = client_argv;
1064 + strvec_pushv(&client.args, client_argv);
1065 if (start_command(&client))
1066 exit(1);
1067 write_or_die(client.in, preamble->buf, preamble->len);
run-command.c
+1 -1
@@ -1039,7 +1039,7 @@ int run_command_v_opt_cd_env_tr2(const char **argv, int opt, const char *dir,
1039 const char *const *env, const char *tr2_class)
1040 {
1041 struct child_process cmd = CHILD_PROCESS_INIT;
1042 - cmd.argv = argv;
1042 + strvec_pushv(&cmd.args, argv);
1043 cmd.no_stdin = opt & RUN_COMMAND_NO_STDIN ? 1 : 0;
1044 cmd.git_cmd = opt & RUN_GIT_CMD ? 1 : 0;
1045 cmd.stdout_to_stderr = opt & RUN_COMMAND_STDOUT_TO_STDERR ? 1 : 0;
t/helper/test-subprocess.c
+1 -1
@@ -15,6 +15,6 @@ int cmd__subprocess(int argc, const char **argv)
15 argv++;
16 }
17 cp.git_cmd = 1;
18 - cp.argv = (const char **)argv + 1;
18 + strvec_pushv(&cp.args, (const char **)argv + 1);
19 return run_command(&cp);
20 }