зеркало из https://github.com/microsoft/git.git
execv_dashed_external: use child_process struct
When we run a dashed external, we use the one-liner run_command_v_opt() to do so. Let's switch to using a child_process struct, which has two advantages: 1. We can drop all of the allocation and cleanup code for building our custom argv array, and just rely on the builtin argv_array (at the minor cost of doing a few extra mallocs). 2. We have access to the complete range of child_process options, not just the ones that the "_opt()" form can forward. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
a274e0a036
Коммит
2b296c93d4
25
git.c
25
git.c
|
@ -575,8 +575,7 @@ static void handle_builtin(int argc, const char **argv)
|
|||
|
||||
static void execv_dashed_external(const char **argv)
|
||||
{
|
||||
struct strbuf cmd = STRBUF_INIT;
|
||||
const char *tmp;
|
||||
struct child_process cmd = CHILD_PROCESS_INIT;
|
||||
int status;
|
||||
|
||||
if (get_super_prefix())
|
||||
|
@ -586,30 +585,20 @@ static void execv_dashed_external(const char **argv)
|
|||
use_pager = check_pager_config(argv[0]);
|
||||
commit_pager_choice();
|
||||
|
||||
strbuf_addf(&cmd, "git-%s", argv[0]);
|
||||
argv_array_pushf(&cmd.args, "git-%s", argv[0]);
|
||||
argv_array_pushv(&cmd.args, argv + 1);
|
||||
cmd.clean_on_exit = 1;
|
||||
cmd.silent_exec_failure = 1;
|
||||
|
||||
/*
|
||||
* argv[0] must be the git command, but the argv array
|
||||
* belongs to the caller, and may be reused in
|
||||
* subsequent loop iterations. Save argv[0] and
|
||||
* restore it on error.
|
||||
*/
|
||||
tmp = argv[0];
|
||||
argv[0] = cmd.buf;
|
||||
|
||||
trace_argv_printf(argv, "trace: exec:");
|
||||
trace_argv_printf(cmd.args.argv, "trace: exec:");
|
||||
|
||||
/*
|
||||
* if we fail because the command is not found, it is
|
||||
* OK to return. Otherwise, we just pass along the status code.
|
||||
*/
|
||||
status = run_command_v_opt(argv, RUN_SILENT_EXEC_FAILURE | RUN_CLEAN_ON_EXIT);
|
||||
status = run_command(&cmd);
|
||||
if (status >= 0 || errno != ENOENT)
|
||||
exit(status);
|
||||
|
||||
argv[0] = tmp;
|
||||
|
||||
strbuf_release(&cmd);
|
||||
}
|
||||
|
||||
static int run_argv(int *argcp, const char ***argv)
|
||||
|
|
Загрузка…
Ссылка в новой задаче