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>

René Scharfe committed May 26, 2024 at 22:16 UTC 36d900d2b0b861d4cb359ddbaa904de90336eb71
1 file changed +4 -8
builtin/difftool.c
+4 -8
@@ -674,19 +674,15 @@ finish:
674 static int run_file_diff(int prompt, const char *prefix,
675 struct child_process *child)
676 {
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");
679 if (prompt > 0)
683 - env[2] = "GIT_DIFFTOOL_PROMPT=true";
680 + strvec_push(&child->env, "GIT_DIFFTOOL_PROMPT=true");
681 else if (!prompt)
685 - env[2] = "GIT_DIFFTOOL_NO_PROMPT=true";
682 + strvec_push(&child->env, "GIT_DIFFTOOL_NO_PROMPT=true");
683
684 child->git_cmd = 1;
685 child->dir = prefix;
689 - strvec_pushv(&child->env, env);
686
687 return run_command(child);
688 }