diff options
Diffstat (limited to 'run-command.c')
-rw-r--r-- | run-command.c | 79 |
1 files changed, 39 insertions, 40 deletions
diff --git a/run-command.c b/run-command.c index 9b3a57d1e3..2ee59acdc8 100644 --- a/run-command.c +++ b/run-command.c @@ -2,7 +2,7 @@ #include "run-command.h" #include "exec-cmd.h" #include "sigchain.h" -#include "argv-array.h" +#include "strvec.h" #include "thread-utils.h" #include "strbuf.h" #include "string-list.h" @@ -11,14 +11,14 @@ void child_process_init(struct child_process *child) { memset(child, 0, sizeof(*child)); - argv_array_init(&child->args); - argv_array_init(&child->env_array); + strvec_init(&child->args); + strvec_init(&child->env_array); } void child_process_clear(struct child_process *child) { - argv_array_clear(&child->args); - argv_array_clear(&child->env_array); + strvec_clear(&child->args); + strvec_clear(&child->env_array); } struct child_to_clean { @@ -263,31 +263,31 @@ int sane_execvp(const char *file, char * const argv[]) return -1; } -static const char **prepare_shell_cmd(struct argv_array *out, const char **argv) +static const char **prepare_shell_cmd(struct strvec *out, const char **argv) { if (!argv[0]) BUG("shell command is empty"); if (strcspn(argv[0], "|&;<>()$`\\\"' \t\n*?[#~=%") != strlen(argv[0])) { #ifndef GIT_WINDOWS_NATIVE - argv_array_push(out, SHELL_PATH); + strvec_push(out, SHELL_PATH); #else - argv_array_push(out, "sh"); + strvec_push(out, "sh"); #endif - argv_array_push(out, "-c"); + strvec_push(out, "-c"); /* * If we have no extra arguments, we do not even need to * bother with the "$@" magic. */ if (!argv[1]) - argv_array_push(out, argv[0]); + strvec_push(out, argv[0]); else - argv_array_pushf(out, "%s \"$@\"", argv[0]); + strvec_pushf(out, "%s \"$@\"", argv[0]); } - argv_array_pushv(out, argv); - return out->argv; + strvec_pushv(out, argv); + return out->v; } #ifndef GIT_WINDOWS_NATIVE @@ -401,7 +401,7 @@ static void child_err_spew(struct child_process *cmd, struct child_err *cerr) set_error_routine(old_errfn); } -static int prepare_cmd(struct argv_array *out, const struct child_process *cmd) +static int prepare_cmd(struct strvec *out, const struct child_process *cmd) { if (!cmd->argv[0]) BUG("command is empty"); @@ -410,14 +410,14 @@ static int prepare_cmd(struct argv_array *out, const struct child_process *cmd) * Add SHELL_PATH so in the event exec fails with ENOEXEC we can * attempt to interpret the command with 'sh'. */ - argv_array_push(out, SHELL_PATH); + strvec_push(out, SHELL_PATH); if (cmd->git_cmd) { prepare_git_cmd(out, cmd->argv); } else if (cmd->use_shell) { prepare_shell_cmd(out, cmd->argv); } else { - argv_array_pushv(out, cmd->argv); + strvec_pushv(out, cmd->argv); } /* @@ -426,13 +426,13 @@ static int prepare_cmd(struct argv_array *out, const struct child_process *cmd) * there are dir separator characters, we have exec attempt to invoke * the command directly. */ - if (!has_dir_sep(out->argv[1])) { - char *program = locate_in_PATH(out->argv[1]); + if (!has_dir_sep(out->v[1])) { + char *program = locate_in_PATH(out->v[1]); if (program) { - free((char *)out->argv[1]); - out->argv[1] = program; + free((char *)out->v[1]); + out->v[1] = program; } else { - argv_array_clear(out); + strvec_clear(out); errno = ENOENT; return -1; } @@ -672,9 +672,9 @@ int start_command(struct child_process *cmd) char *str; if (!cmd->argv) - cmd->argv = cmd->args.argv; + cmd->argv = cmd->args.v; if (!cmd->env) - cmd->env = cmd->env_array.argv; + cmd->env = cmd->env_array.v; /* * In case of errors we must keep the promise to close FDs @@ -742,7 +742,7 @@ fail_pipe: int notify_pipe[2]; int null_fd = -1; char **childenv; - struct argv_array argv = ARGV_ARRAY_INIT; + struct strvec argv = STRVEC_INIT; struct child_err cerr; struct atfork_state as; @@ -846,10 +846,10 @@ fail_pipe: * be used in the event exec failed with ENOEXEC at which point * we will try to interpret the command using 'sh'. */ - execve(argv.argv[1], (char *const *) argv.argv + 1, + execve(argv.v[1], (char *const *) argv.v + 1, (char *const *) childenv); if (errno == ENOEXEC) - execve(argv.argv[0], (char *const *) argv.argv, + execve(argv.v[0], (char *const *) argv.v, (char *const *) childenv); if (errno == ENOENT) { @@ -888,7 +888,7 @@ fail_pipe: if (null_fd >= 0) close(null_fd); - argv_array_clear(&argv); + strvec_clear(&argv); free(childenv); } end_of_spawn: @@ -897,7 +897,7 @@ end_of_spawn: { int fhin = 0, fhout = 1, fherr = 2; const char **sargv = cmd->argv; - struct argv_array nargv = ARGV_ARRAY_INIT; + struct strvec nargv = STRVEC_INIT; if (cmd->no_stdin) fhin = open("/dev/null", O_RDWR); @@ -935,7 +935,7 @@ end_of_spawn: if (cmd->clean_on_exit && cmd->pid >= 0) mark_child_for_cleanup(cmd->pid, cmd); - argv_array_clear(&nargv); + strvec_clear(&nargv); cmd->argv = sargv; if (fhin != 0) close(fhin); @@ -1039,6 +1039,7 @@ int run_command_v_opt_cd_env_tr2(const char **argv, int opt, const char *dir, cmd.silent_exec_failure = opt & RUN_SILENT_EXEC_FAILURE ? 1 : 0; cmd.use_shell = opt & RUN_USING_SHELL ? 1 : 0; cmd.clean_on_exit = opt & RUN_CLEAN_ON_EXIT ? 1 : 0; + cmd.wait_after_clean = opt & RUN_WAIT_AFTER_CLEAN ? 1 : 0; cmd.dir = dir; cmd.env = env; cmd.trace2_child_class = tr2_class; @@ -1351,9 +1352,9 @@ int run_hook_ve(const char *const *env, const char *name, va_list args) if (!p) return 0; - argv_array_push(&hook.args, p); + strvec_push(&hook.args, p); while ((p = va_arg(args, const char *))) - argv_array_push(&hook.args, p); + strvec_push(&hook.args, p); hook.env = env; hook.no_stdin = 1; hook.stdout_to_stderr = 1; @@ -1865,15 +1866,13 @@ int run_processes_parallel_tr2(int n, get_next_task_fn get_next_task, return result; } -int run_auto_gc(int quiet) +int run_auto_maintenance(int quiet) { - struct argv_array argv_gc_auto = ARGV_ARRAY_INIT; - int status; + struct child_process maint = CHILD_PROCESS_INIT; - argv_array_pushl(&argv_gc_auto, "gc", "--auto", NULL); - if (quiet) - argv_array_push(&argv_gc_auto, "--quiet"); - status = run_command_v_opt(argv_gc_auto.argv, RUN_GIT_CMD); - argv_array_clear(&argv_gc_auto); - return status; + maint.git_cmd = 1; + strvec_pushl(&maint.args, "maintenance", "run", "--auto", NULL); + strvec_push(&maint.args, quiet ? "--quiet" : "--no-quiet"); + + return run_command(&maint); } |