* [PATCH 1/1] git-config: git-config --list fixed when GIT_CONFIG value starts with ~/
@ 2014-11-14 18:29 0xAX
2014-11-14 19:19 ` Eric Sunshine
2014-11-14 20:10 ` Junio C Hamano
0 siblings, 2 replies; 6+ messages in thread
From: 0xAX @ 2014-11-14 18:29 UTC (permalink / raw)
To: git@vger.kernel.org; +Cc: 0xAX, Alex Kuleshov
When we execute git config --list and $GIT_CONFIG value starts with home
prefix - ~/ it produces folowing error - fatal: unable to read config
file '~/.gitconfig': No such file or directory. This patch fixed it with
expand_user_path for configuration file path before git-config --list
call.
Signed-off-by: Alex Kuleshov <kuleshovmail@gmial.com>
Signed-off-by: 0xAX <kuleshovmail@gmail.com>
---
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 (git_config_with_options(show_all_config, NULL,
&given_config_source,
respect_includes) < 0) {
--
2.1.3.17.g7fa1365.dirty
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1] git-config: git-config --list fixed when GIT_CONFIG value starts with ~/
2014-11-14 18:29 [PATCH 1/1] git-config: git-config --list fixed when GIT_CONFIG value starts with ~/ 0xAX
@ 2014-11-14 19:19 ` Eric Sunshine
2014-11-14 19:30 ` Jeff King
2014-11-14 20:10 ` Junio C Hamano
1 sibling, 1 reply; 6+ messages in thread
From: Eric Sunshine @ 2014-11-14 19:19 UTC (permalink / raw)
To: 0xAX; +Cc: git@vger.kernel.org, Alex Kuleshov
On Fri, Nov 14, 2014 at 1:29 PM, 0xAX <kuleshovmail@gmail.com> wrote:
> When we execute git config --list and $GIT_CONFIG value starts with home
> prefix - ~/ it produces folowing error - fatal: unable to read config
> file '~/.gitconfig': No such file or directory. This patch fixed it with
> expand_user_path for configuration file path before git-config --list
> call.
Is this special case really warranted? Elsewhere, GIT_CONFIG does not
get this sort of special treatment. Moreover, it appears that no other
GIT_* environment variable is subject to such special treatment. (And,
generally speaking, on Unix, it is generally assumed that a path
assigned to an environment variable is to be used as-is.)
> Signed-off-by: Alex Kuleshov <kuleshovmail@gmial.com>
s/gmial/gmail/
> Signed-off-by: 0xAX <kuleshovmail@gmail.com>
> ---
> 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;
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.
> if (git_config_with_options(show_all_config, NULL,
> &given_config_source,
> respect_includes) < 0) {
> --
> 2.1.3.17.g7fa1365.dirty
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1] git-config: git-config --list fixed when GIT_CONFIG value starts with ~/
2014-11-14 19:19 ` Eric Sunshine
@ 2014-11-14 19:30 ` Jeff King
2014-11-14 19:38 ` Alex Kuleshov
0 siblings, 1 reply; 6+ messages in thread
From: Jeff King @ 2014-11-14 19:30 UTC (permalink / raw)
To: Eric Sunshine; +Cc: 0xAX, git@vger.kernel.org, Alex Kuleshov
On Fri, Nov 14, 2014 at 02:19:41PM -0500, Eric Sunshine wrote:
> On Fri, Nov 14, 2014 at 1:29 PM, 0xAX <kuleshovmail@gmail.com> wrote:
> > When we execute git config --list and $GIT_CONFIG value starts with home
> > prefix - ~/ it produces folowing error - fatal: unable to read config
> > file '~/.gitconfig': No such file or directory. This patch fixed it with
> > expand_user_path for configuration file path before git-config --list
> > call.
>
> Is this special case really warranted? Elsewhere, GIT_CONFIG does not
> get this sort of special treatment. Moreover, it appears that no other
> GIT_* environment variable is subject to such special treatment. (And,
> generally speaking, on Unix, it is generally assumed that a path
> assigned to an environment variable is to be used as-is.)
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.
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1] git-config: git-config --list fixed when GIT_CONFIG value starts with ~/
2014-11-14 19:30 ` Jeff King
@ 2014-11-14 19:38 ` Alex Kuleshov
2014-11-14 20:04 ` Jeff King
0 siblings, 1 reply; 6+ messages in thread
From: Alex Kuleshov @ 2014-11-14 19:38 UTC (permalink / raw)
To: Jeff King; +Cc: Eric Sunshine, 0xAX, git@vger.kernel.org
Hello Eric and Jeff,
>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.
>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.
>
> 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1] git-config: git-config --list fixed when GIT_CONFIG value starts with ~/
2014-11-14 19:38 ` Alex Kuleshov
@ 2014-11-14 20:04 ` Jeff King
0 siblings, 0 replies; 6+ messages in thread
From: Jeff King @ 2014-11-14 20:04 UTC (permalink / raw)
To: Alex Kuleshov; +Cc: Eric Sunshine, git@vger.kernel.org
On Sat, Nov 15, 2014 at 01:38:36AM +0600, Alex Kuleshov wrote:
> > 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.
Weird. It seems to work fine for me (though I admit I only did a pretty
cursory test).
> > 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.
> >
> What if we'll put path expanding right after getting value of file path,
> after given_config_source.file = getenv(CONFIG_ENVIRONMENT); at 451?
That is a good place to put it if you want to impact $GIT_CONFIG but not
"--file". I am not sure if that is sensible. But then, I am not sure
that I am convinced that we should be making any change at all.
-Peff
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1] git-config: git-config --list fixed when GIT_CONFIG value starts with ~/
2014-11-14 18:29 [PATCH 1/1] git-config: git-config --list fixed when GIT_CONFIG value starts with ~/ 0xAX
2014-11-14 19:19 ` Eric Sunshine
@ 2014-11-14 20:10 ` Junio C Hamano
1 sibling, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2014-11-14 20:10 UTC (permalink / raw)
To: 0xAX; +Cc: git@vger.kernel.org, Alex Kuleshov
0xAX <kuleshovmail@gmail.com> writes:
> When we execute git config --list and $GIT_CONFIG value starts with home
> prefix - ~/ it produces folowing error - fatal: unable to read config
> file '~/.gitconfig': No such file or directory. This patch fixed it with
> expand_user_path for configuration file path before git-config --list
> call.
Expanding tilde ~ in environment variables is what you let your
shell do when you assign it. This is not limited to Git:
$ FOO=~/.bashrc
$ BAR='~/.bashrc'
$ head -n 1 "$FOO"
# Bourne Again SHell init file.
$ head -n 1 "$BAR"
head: cannot open ‘~/.bashrc’ for reading: No such file rdirectory
$ echo "FOO=$FOO" "BAR=$BAR"
FOO=/home/gitster/.bashrc BAR=~/.bashrc
The patch does not fix anything and not necessary.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-11-14 20:10 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-14 18:29 [PATCH 1/1] git-config: git-config --list fixed when GIT_CONFIG value starts with ~/ 0xAX
2014-11-14 19:19 ` Eric Sunshine
2014-11-14 19:30 ` Jeff King
2014-11-14 19:38 ` Alex Kuleshov
2014-11-14 20:04 ` Jeff King
2014-11-14 20:10 ` Junio C Hamano
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).