* [PATCH] difftool: add env vars directly in run_file_diff()
@ 2024-05-26 20:16 René Scharfe
2024-05-29 7:57 ` Patrick Steinhardt
0 siblings, 1 reply; 3+ messages in thread
From: René Scharfe @ 2024-05-26 20:16 UTC (permalink / raw)
To: Git List
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] difftool: add env vars directly in run_file_diff()
2024-05-26 20:16 [PATCH] difftool: add env vars directly in run_file_diff() René Scharfe
@ 2024-05-29 7:57 ` Patrick Steinhardt
2024-06-01 20:23 ` René Scharfe
0 siblings, 1 reply; 3+ messages in thread
From: Patrick Steinhardt @ 2024-05-29 7:57 UTC (permalink / raw)
To: René Scharfe; +Cc: Git List
[-- Attachment #1: Type: text/plain, Size: 769 bytes --]
On Sun, May 26, 2024 at 10:16:50PM +0200, René Scharfe wrote:
> 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>
I don't know whether this may cause more allocations. But even if it
did, it would very much feel like a micro-optimization that is not worth
it in the end given that we're about to spawn a new process anyway,
which is way more expensive.
So favoring readability/maintainability very much feels like the right
thing to do here, and the result looks good to me. Thanks!
Patrick
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] difftool: add env vars directly in run_file_diff()
2024-05-29 7:57 ` Patrick Steinhardt
@ 2024-06-01 20:23 ` René Scharfe
0 siblings, 0 replies; 3+ messages in thread
From: René Scharfe @ 2024-06-01 20:23 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: Git List
Am 29.05.24 um 09:57 schrieb Patrick Steinhardt:
> On Sun, May 26, 2024 at 10:16:50PM +0200, René Scharfe wrote:
>> 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>
>
> I don't know whether this may cause more allocations.
It doesn't -- strvec_pushv() calls strvec_push() in a loop, the
patch just unrolls it.
René
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-06-01 20:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-26 20:16 [PATCH] difftool: add env vars directly in run_file_diff() René Scharfe
2024-05-29 7:57 ` Patrick Steinhardt
2024-06-01 20:23 ` René Scharfe
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).