From: "René Scharfe" <l.s.r@web.de>
To: Git List <git@vger.kernel.org>
Subject: [PATCH] difftool: add env vars directly in run_file_diff()
Date: Sun, 26 May 2024 22:16:50 +0200 [thread overview]
Message-ID: <c7c843b9-0ccf-4bcb-a036-d794729a99d6@web.de> (raw)
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 reply other threads:[~2024-05-26 20:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-26 20:16 René Scharfe [this message]
2024-05-29 7:57 ` [PATCH] difftool: add env vars directly in run_file_diff() Patrick Steinhardt
2024-06-01 20:23 ` René Scharfe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c7c843b9-0ccf-4bcb-a036-d794729a99d6@web.de \
--to=l.s.r@web.de \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).