use child_process members "args" and "env" directly

Build argument list and environment of child processes by using
struct child_process and populating its members "args" and "env"
directly instead of maintaining separate strvecs and letting
run_command_v_opt() and friends populate these members.  This is
simpler, shorter and slightly more efficient.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
This commit is contained in:
René Scharfe
2022-10-30 12:51:14 +01:00
committed by Taylor Blau
parent 4120294cbf
commit 0e90673957
13 changed files with 185 additions and 206 deletions

View File

@ -1510,37 +1510,35 @@ static int update(int argc, const char **argv, const char *prefix)
N_("prune remotes after fetching")),
OPT_END()
};
struct strvec fetch_argv = STRVEC_INIT;
struct child_process cmd = CHILD_PROCESS_INIT;
int default_defined = 0;
int retval;
argc = parse_options(argc, argv, prefix, options,
builtin_remote_update_usage,
PARSE_OPT_KEEP_ARGV0);
strvec_push(&fetch_argv, "fetch");
strvec_push(&cmd.args, "fetch");
if (prune != -1)
strvec_push(&fetch_argv, prune ? "--prune" : "--no-prune");
strvec_push(&cmd.args, prune ? "--prune" : "--no-prune");
if (verbose)
strvec_push(&fetch_argv, "-v");
strvec_push(&fetch_argv, "--multiple");
strvec_push(&cmd.args, "-v");
strvec_push(&cmd.args, "--multiple");
if (argc < 2)
strvec_push(&fetch_argv, "default");
strvec_push(&cmd.args, "default");
for (i = 1; i < argc; i++)
strvec_push(&fetch_argv, argv[i]);
strvec_push(&cmd.args, argv[i]);
if (strcmp(fetch_argv.v[fetch_argv.nr-1], "default") == 0) {
if (strcmp(cmd.args.v[cmd.args.nr-1], "default") == 0) {
git_config(get_remote_default, &default_defined);
if (!default_defined) {
strvec_pop(&fetch_argv);
strvec_push(&fetch_argv, "--all");
strvec_pop(&cmd.args);
strvec_push(&cmd.args, "--all");
}
}
retval = run_command_v_opt(fetch_argv.v, RUN_GIT_CMD);
strvec_clear(&fetch_argv);
return retval;
cmd.git_cmd = 1;
return run_command(&cmd);
}
static int remove_all_fetch_refspecs(const char *key)