]> git.ipfire.org Git - thirdparty/git.git/commitdiff
difftool: add env vars directly in run_file_diff()
authorRené Scharfe <l.s.r@web.de>
Sun, 26 May 2024 20:16:50 +0000 (22:16 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 27 May 2024 15:55:59 +0000 (08:55 -0700)
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>
builtin/difftool.c

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