difftool: add env vars directly in run_file_diff()

Add the environment variables of the child process directly using
strvec_push() instead of building an array out of them and then adding
that using strvec_pushv().  The new code is shorter and avoids magic
array index values and fragile array padding.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
René Scharfe 2024-05-26 22:16:50 +02:00 committed by Junio C Hamano
parent 786a3e4b8d
commit 36d900d2b0

View file

@ -674,19 +674,15 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
static int run_file_diff(int prompt, const char *prefix, static int run_file_diff(int prompt, const char *prefix,
struct child_process *child) struct child_process *child)
{ {
const char *env[] = { strvec_push(&child->env, "GIT_PAGER=");
"GIT_PAGER=", "GIT_EXTERNAL_DIFF=git-difftool--helper", NULL, strvec_push(&child->env, "GIT_EXTERNAL_DIFF=git-difftool--helper");
NULL
};
if (prompt > 0) if (prompt > 0)
env[2] = "GIT_DIFFTOOL_PROMPT=true"; strvec_push(&child->env, "GIT_DIFFTOOL_PROMPT=true");
else if (!prompt) else if (!prompt)
env[2] = "GIT_DIFFTOOL_NO_PROMPT=true"; strvec_push(&child->env, "GIT_DIFFTOOL_NO_PROMPT=true");
child->git_cmd = 1; child->git_cmd = 1;
child->dir = prefix; child->dir = prefix;
strvec_pushv(&child->env, env);
return run_command(child); return run_command(child);
} }