Skip to content

Commit 36d900d

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 786a3e4 commit 36d900d

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

builtin/difftool.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -674,19 +674,15 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
674674
static int run_file_diff(int prompt, const char *prefix,
675675
struct child_process *child)
676676
{
677-
const char *env[] = {
678-
"GIT_PAGER=", "GIT_EXTERNAL_DIFF=git-difftool--helper", NULL,
679-
NULL
680-
};
681-
677+
strvec_push(&child->env, "GIT_PAGER=");
678+
strvec_push(&child->env, "GIT_EXTERNAL_DIFF=git-difftool--helper");
682679
if (prompt > 0)
683-
env[2] = "GIT_DIFFTOOL_PROMPT=true";
680+
strvec_push(&child->env, "GIT_DIFFTOOL_PROMPT=true");
684681
else if (!prompt)
685-
env[2] = "GIT_DIFFTOOL_NO_PROMPT=true";
682+
strvec_push(&child->env, "GIT_DIFFTOOL_NO_PROMPT=true");
686683

687684
child->git_cmd = 1;
688685
child->dir = prefix;
689-
strvec_pushv(&child->env, env);
690686

691687
return run_command(child);
692688
}

0 commit comments

Comments
 (0)