]> git.ipfire.org Git - thirdparty/git.git/commitdiff
run-command API users: use strvec_pushv(), not argv assignment
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Thu, 25 Nov 2021 22:52:18 +0000 (23:52 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 26 Nov 2021 06:15:07 +0000 (22:15 -0800)
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>
add-patch.c
daemon.c
http-backend.c
http.c
remote-curl.c
run-command.c
t/helper/test-subprocess.c

index 8c41cdfe39be041e7d119737a83d754a06733649..573eef0cc4a86642bc92fba74763aaa913af1b2f 100644 (file)
@@ -413,7 +413,7 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
                strvec_push(&args, ps->items[i].original);
 
        setup_child_process(s, &cp, NULL);
-       cp.argv = args.v;
+       strvec_pushv(&cp.args, args.v);
        res = capture_command(&cp, plain, 0);
        if (res) {
                strvec_clear(&args);
@@ -431,7 +431,7 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
 
                setup_child_process(s, &colored_cp, NULL);
                xsnprintf((char *)args.v[color_arg_index], 8, "--color");
-               colored_cp.argv = args.v;
+               strvec_pushv(&colored_cp.args, args.v);
                colored = &s->colored;
                res = capture_command(&colored_cp, colored, 0);
                strvec_clear(&args);
index b1fcbe0d6fa847dd936467c0d8d1aeffbf90d1cc..8df21f2130ccfcbd1247a1c6f182ec858e8e8337 100644 (file)
--- a/daemon.c
+++ b/daemon.c
@@ -922,7 +922,7 @@ static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen)
 #endif
        }
 
-       cld.argv = cld_argv.v;
+       strvec_pushv(&cld.args, cld_argv.v);
        cld.in = incoming;
        cld.out = dup(incoming);
 
index 3d6e2ff17f83c7c5d1fd42578f9dc073686becab..4dd4d939f8a8b5be869041ca72687fe7654da141 100644 (file)
@@ -480,7 +480,7 @@ static void run_service(const char **argv, int buffer_input)
                strvec_pushf(&cld.env_array,
                             "GIT_COMMITTER_EMAIL=%s@http.%s", user, host);
 
-       cld.argv = argv;
+       strvec_pushv(&cld.args, argv);
        if (buffer_input || gzipped_request || req_len >= 0)
                cld.in = -1;
        cld.git_cmd = 1;
diff --git a/http.c b/http.c
index f92859f43fa53e0352b239ca43a769c5f9ff4aae..229da4d14882d9c9855ab418ad64f30fe62e485a 100644 (file)
--- a/http.c
+++ b/http.c
@@ -2126,8 +2126,9 @@ int finish_http_pack_request(struct http_pack_request *preq)
 
        ip.git_cmd = 1;
        ip.in = tmpfile_fd;
-       ip.argv = preq->index_pack_args ? preq->index_pack_args
-                                       : default_index_pack_args;
+       strvec_pushv(&ip.args, preq->index_pack_args ?
+                    preq->index_pack_args :
+                    default_index_pack_args);
 
        if (preq->preserve_index_pack_stdout)
                ip.out = 0;
index d69156312bda65c7f081a0bfd8c91b043f676487..0dabef2dd7c565f3f2c2ecd74a0ca295bd874afb 100644 (file)
@@ -1061,7 +1061,7 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads,
        client.in = -1;
        client.out = -1;
        client.git_cmd = 1;
-       client.argv = client_argv;
+       strvec_pushv(&client.args, client_argv);
        if (start_command(&client))
                exit(1);
        write_or_die(client.in, preamble->buf, preamble->len);
index f40df01c77247c404062c9dfcbb9dddf534544e1..620a06ca2f56d54802d50db7ebcfdb855cb617a9 100644 (file)
@@ -1039,7 +1039,7 @@ int run_command_v_opt_cd_env_tr2(const char **argv, int opt, const char *dir,
                                 const char *const *env, const char *tr2_class)
 {
        struct child_process cmd = CHILD_PROCESS_INIT;
-       cmd.argv = argv;
+       strvec_pushv(&cmd.args, argv);
        cmd.no_stdin = opt & RUN_COMMAND_NO_STDIN ? 1 : 0;
        cmd.git_cmd = opt & RUN_GIT_CMD ? 1 : 0;
        cmd.stdout_to_stderr = opt & RUN_COMMAND_STDOUT_TO_STDERR ? 1 : 0;
index 92b69de635296d32d38d1f7d7589d5f8b6fbc296..ff22f2fa2c57efbda1246f1aab0da494eb026fd1 100644 (file)
@@ -15,6 +15,6 @@ int cmd__subprocess(int argc, const char **argv)
                argv++;
        }
        cp.git_cmd = 1;
-       cp.argv = (const char **)argv + 1;
+       strvec_pushv(&cp.args, (const char **)argv + 1);
        return run_command(&cp);
 }