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

Re: [PATCH 1/1] git-config: git-config --list fixed when GIT_CONFIG value starts with ~/

From
Alex Kuleshov <kuleshovmail@gmail.com>
Date
Nov 14, 2014, 19:38 UTC
Message-ID
<87vbmh8syq.fsf@gmail.com>
In-Reply-To
<20141114193049.GB10860@peff.net>
Hello Eric and Jeff,
Show 14 quoted lines
>Eric Sunshine
>A few issues:
>
>(1) Style: s/char* /char */
>
>(2) Avoid declaration (of 'newpath') after statement.
>
>(3) You can drop 'newpath' altogether and just assign the result of
>expand_user_path() directly to given_config_source.file.
>
>This code is potentially leaking the old value of
>given_config_source.file, and (later) the new value, however, as
>given_config_source.file is already being leaked elsewhere, it
>probably does not make the situation much worse.

It is my first patch to git's code base, so many thanks for your feedback, i'll fix these issues if there will be need in this patch.

Show 10 quoted lines
>Jeff King <peff@peff.net>
>
> Yeah, I'd agree it is a little unexpected to expand here. The "~" is
> mostly a shell thing, and doing:
>
>   GIT_CONFIG=~/.gitconfig git config --list
>
> from the shell generally works, because the shell will expand the "~"
> before it even hits git. If you're not using a shell to set the
> variable, you probably should be pre-expanding it yourself.

Yes, you're right here, but i put GIT_CONFIG=~/.gitconfig to my .bashrc and it doesn't work so.

Show 32 quoted lines
>
> Note that this code path affects "git config --file=~/.gitconfig", too.
> At least there it would be a little bit useful because the shell will
> not expand for you, but it still feels a bit unconventional to me.
>
>> >  builtin/config.c | 2 ++
>> >  1 file changed, 2 insertions(+)
>> >
>> > diff --git a/builtin/config.c b/builtin/config.c
>> > index 7bba516..df1bee0 100644
>> > --- a/builtin/config.c
>> > +++ b/builtin/config.c
>> > @@ -540,6 +540,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
>> >
>> >         if (actions == ACTION_LIST) {
>> >                 check_argc(argc, 0, 0);
>> > +               const char* newpath = expand_user_path(given_config_source.file);
>> > +               given_config_source.file = newpath;
>
> If we _were_ going to do such an expansion, this is absolutely the wrong
> place for it. It works only for the "--list" action; if we are going to
> expand it, we would want to do so everywhere. And we do not even know if
> given_config_source.file is non-NULL here (we could be reading from
> stdin, or a blob). Fortunately expand_user_path will pass through a NULL
> without segfaulting.
>
> Probably the right place would be the if/else chain around
> builtin/config.c:514, where we convert a relative path into an absolute
> one. But I'm not convinced it's a good thing to be doing in the first
> place.
>
> -Peff

What if we'll put path expanding right after getting value of file path, after given_config_source.file = getenv(CONFIG_ENVIRONMENT); at 451?

Thank you.

-- Best regards. 0xAX

Previous: Jeff KingNext: Jeff King
Message 4 of 6 in “git-config: git-config --list fixed when GIT_CONFIG value starts with ~/”
  1. 1/1 git-config: git-config --list fixed when GIT_CONFIG value starts with ~/0xAX, Nov 14, 2014
  2. Eric SunshineNov 14, 2014
  3. Jeff KingNov 14, 2014
  4. Alex KuleshovNov 14, 2014
  5. Jeff KingNov 14, 2014
  6. Junio C HamanoNov 14, 2014

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.