git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] difftool: add env vars directly in run_file_diff()

From
René Scharfe <l.s.r@web.de>
Date
May 26, 2024, 20:16 UTC
Message-ID
<c7c843b9-0ccf-4bcb-a036-d794729a99d6@web.de>

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>
---
 builtin/difftool.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/builtin/difftool.c b/builtin/difftool.c
index a130faae4f..a1794b7eed 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -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,
 			 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);
 }
--
2.45.1
Next: Patrick Steinhardt
Message 1 of 3 in “difftool: add env vars directly in run_file_diff()”
  1. difftool: add env vars directly in run_file_diff()René Scharfe, May 26, 2024
  2. Patrick SteinhardtMay 29, 2024
  3. René ScharfeJun 1, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.