Skip to content

Commit 2b296c9

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a274e0a commit 2b296c9

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

git.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -575,8 +575,7 @@ static void handle_builtin(int argc, const char **argv)
575575

576576
static void execv_dashed_external(const char **argv)
577577
{
578-
struct strbuf cmd = STRBUF_INIT;
579-
const char *tmp;
578+
struct child_process cmd = CHILD_PROCESS_INIT;
580579
int status;
581580

582581
if (get_super_prefix())
@@ -586,30 +585,20 @@ static void execv_dashed_external(const char **argv)
586585
use_pager = check_pager_config(argv[0]);
587586
commit_pager_choice();
588587

589-
strbuf_addf(&cmd, "git-%s", argv[0]);
588+
argv_array_pushf(&cmd.args, "git-%s", argv[0]);
589+
argv_array_pushv(&cmd.args, argv + 1);
590+
cmd.clean_on_exit = 1;
591+
cmd.silent_exec_failure = 1;
590592

591-
/*
592-
* argv[0] must be the git command, but the argv array
593-
* belongs to the caller, and may be reused in
594-
* subsequent loop iterations. Save argv[0] and
595-
* restore it on error.
596-
*/
597-
tmp = argv[0];
598-
argv[0] = cmd.buf;
599-
600-
trace_argv_printf(argv, "trace: exec:");
593+
trace_argv_printf(cmd.args.argv, "trace: exec:");
601594

602595
/*
603596
* if we fail because the command is not found, it is
604597
* OK to return. Otherwise, we just pass along the status code.
605598
*/
606-
status = run_command_v_opt(argv, RUN_SILENT_EXEC_FAILURE | RUN_CLEAN_ON_EXIT);
599+
status = run_command(&cmd);
607600
if (status >= 0 || errno != ENOENT)
608601
exit(status);
609-
610-
argv[0] = tmp;
611-
612-
strbuf_release(&cmd);
613602
}
614603

615604
static int run_argv(int *argcp, const char ***argv)

0 commit comments

Comments
 (0)