difftool: use run_command() API in run_file_diff()

Change the run_file_diff() function to use the run_command() API
directly, instead of invoking the run_command_v_opt_cd_env() wrapper.

This allows it, like run_dir_diff(), to use the "args" from "struct
strvec", instead of the "const char **argv" passed into
cmd_difftool(). This will be used in the subsequent commit to get rid
of OPT_ARGUMENT() from cmd_difftool().

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Ævar Arnfjörð Bjarmason 2021-09-13 05:35:39 +02:00 коммит произвёл Junio C Hamano
Родитель b4c7aab7b9
Коммит cc5b594788
1 изменённых файлов: 6 добавлений и 7 удалений

Просмотреть файл

@ -663,24 +663,23 @@ finish:
} }
static int run_file_diff(int prompt, const char *prefix, static int run_file_diff(int prompt, const char *prefix,
int argc, const char **argv) struct child_process *child)
{ {
struct strvec args = STRVEC_INIT;
const char *env[] = { const char *env[] = {
"GIT_PAGER=", "GIT_EXTERNAL_DIFF=git-difftool--helper", NULL, "GIT_PAGER=", "GIT_EXTERNAL_DIFF=git-difftool--helper", NULL,
NULL NULL
}; };
int i;
if (prompt > 0) if (prompt > 0)
env[2] = "GIT_DIFFTOOL_PROMPT=true"; env[2] = "GIT_DIFFTOOL_PROMPT=true";
else if (!prompt) else if (!prompt)
env[2] = "GIT_DIFFTOOL_NO_PROMPT=true"; env[2] = "GIT_DIFFTOOL_NO_PROMPT=true";
child->git_cmd = 1;
child->dir = prefix;
strvec_pushv(&child->env_array, env);
for (i = 0; i < argc; i++) return run_command(child);
strvec_push(&args, argv[i]);
return run_command_v_opt_cd_env(args.v, RUN_GIT_CMD, prefix, env);
} }
int cmd_difftool(int argc, const char **argv, const char *prefix) int cmd_difftool(int argc, const char **argv, const char *prefix)
@ -770,5 +769,5 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
if (dir_diff) if (dir_diff)
return run_dir_diff(extcmd, symlinks, prefix, &child); return run_dir_diff(extcmd, symlinks, prefix, &child);
return run_file_diff(prompt, prefix, child.args.nr, child.args.v); return run_file_diff(prompt, prefix, &child);
} }