threads / discuss / 61985

builtin/config: --name-only doesn't imply --show-names in "git config get"

Subject: builtin/config: --name-only doesn't imply --show-names in "git config get"

## tl;dr

6 messages between Aug 21, 2024 and Aug 22, 2024.

replies: 5people: 3as markdown or json

Yukai Chou· Aug 21, 2024, 08:10 UTC · lore
The v2.46.0 doc of git-config(1) says
> --name-only
> Output only the names of config variables for `list` or `get`.
https://git-scm.com/docs/git-config#Documentation/git-config.txt---name-only

But the behavior of --name-only is more like "disable non-name outputs and leave the output state of names as-is". Thus using --name-only alone, one gets totally empty lines (which might be weird); only using --name-only and --show-names together, can one get output of just names.

# get empty line(s) git config get --all --name-only remote.origin.fetch # get lines of name(s) git config get --all --show-names --name-only remote.origin.fetch

Either the doc or the behavior of --name-only needs some adjustment.
Yukai Chou
Junio C Hamano· Aug 21, 2024, 16:06 UTC · re: Yukai Chou · lore

Re: builtin/config: --name-only doesn't imply --show-names in "git config get"

Yukai Chou <muzimuzhi@gmail.com> writes:
Show 18 quoted lines
> The v2.46.0 doc of git-config(1) says
>
>> --name-only
>> Output only the names of config variables for `list` or `get`.
> https://git-scm.com/docs/git-config#Documentation/git-config.txt---name-only
>
> But the behavior of --name-only is more like "disable non-name outputs
> and leave the output state of names as-is". Thus using --name-only
> alone, one gets totally empty lines (which might be weird); only using
> --name-only and --show-names together, can one get output of just
> names.
>
> # get empty line(s)
> git config get --all --name-only remote.origin.fetch
> # get lines of name(s)
> git config get --all --show-names --name-only remote.origin.fetch
>
> Either the doc or the behavior of --name-only needs some adjustment.

This argues for making "all" imply we need to show the name of the configuration variable, and introducing an option "--hide-name" to omit the name. That way, you'd need to give clearly contradicting "--hide-name" and "--name-only" together to get a nonsense output.

Yukai Chou· Aug 21, 2024, 20:28 UTC · re: Junio C Hamano · lore

Re: builtin/config: --name-only doesn't imply --show-names in "git config get"

Junio C Hamano <gitster@pobox.com> 于2024年8月22日周四 00:07写道:
Show 12 quoted lines
>
> Yukai Chou <muzimuzhi@gmail.com> writes:
>
> > # get empty line(s)
> > git config get --all --name-only remote.origin.fetch
> > # get lines of name(s)
> > git config get --all --show-names --name-only remote.origin.fetch
> >
> > Either the doc or the behavior of --name-only needs some adjustment.
>
> This argues for making "all" imply we need to show the name of the
> configuration variable,
Sorry can you elaborate on what that "all" meant? A new option "--show-all"?
> and introducing an option "--hide-name" to
> omit the name.  That way, you'd need to give clearly contradicting
> "--hide-name" and "--name-only" together to get a nonsense output.

I have a feeling that finally a collection of options shared by "git config list" and "git config get" will be introduced to fully control what they output, and even make the form of output given by one of "git config list" and "git config get" look exactly like the other.

An ideal design:

--show-all --[no-]show-scope --[no-]show-origin --[no-]show-name --[no-]show-value --hide-all --separator=<sep> # fuzzy name?

Initial options
- git config list: --hide-all --show-name --show-value --separator="="
- git config get: --hide-all --show-value --separator=" "
The drawback is, quite some combinations of such options are nonsense.
Yukai
Junio C Hamano· Aug 21, 2024, 20:59 UTC · re: Yukai Chou · lore

Re: builtin/config: --name-only doesn't imply --show-names in "git config get"

Yukai Chou <muzimuzhi@gmail.com> writes:
Show 15 quoted lines
> Junio C Hamano <gitster@pobox.com> 于2024年8月22日周四 00:07写道:
>>
>> Yukai Chou <muzimuzhi@gmail.com> writes:
>>
>> > # get empty line(s)
>> > git config get --all --name-only remote.origin.fetch
>> > # get lines of name(s)
>> > git config get --all --show-names --name-only remote.origin.fetch
>> >
>> > Either the doc or the behavior of --name-only needs some adjustment.
>>
>> This argues for making "all" imply we need to show the name of the
>> configuration variable,
>
> Sorry can you elaborate on what that "all" meant? A new option "--show-all"?
Sorry, but "--all" is probably a red herring.
What I wanted to say was that we can 
 (1) get rid of "--show-name",
 (2) have the combination of options that can emit values for more
    than one key to automatically show both name and value, and
 (3) add "--hide-name" so that such command can still show only the
     value.

where I mixed up (2) and "all". In fact, "--all" is not something that gives values for more than one key (it is things like regexp and urlmatch).

For example:
 $ git config --get-regexp 'sendemail\..*'

would show values for more than one variable, and depending on the variable, it may show the values for one variable more than once. According to the documentation, this was replaced with

    --get-regexp <name-regexp>::
            Replaced by `git config get --all --show-names --regexp <name-regexp>`.
but it could have been
    git config get --all --regexp <name-regexp>
as it is clear --regexp could give results for more than one key.

This points at a bug in the documentation, by the way. "git config --get-all" is described like so:

    --get-all <name> [<value-pattern>]::
            Replaced by `git config get [--value=<pattern>] --all --show-names <name>`.

but this gives values for only one key, and the command does not show key names. It is replaced by

	git config get [--value=<pattern>] --all <name>
without "--show-names".
Patrick Steinhardt· Aug 22, 2024, 05:57 UTC · re: Junio C Hamano · lore

Re: builtin/config: --name-only doesn't imply --show-names in "git config get"

On Wed, Aug 21, 2024 at 01:59:43PM -0700, Junio C Hamano wrote:
Show 33 quoted lines
> Yukai Chou <muzimuzhi@gmail.com> writes:
> 
> > Junio C Hamano <gitster@pobox.com> 于2024年8月22日周四 00:07写道:
> >>
> >> Yukai Chou <muzimuzhi@gmail.com> writes:
> >>
> >> > # get empty line(s)
> >> > git config get --all --name-only remote.origin.fetch
> >> > # get lines of name(s)
> >> > git config get --all --show-names --name-only remote.origin.fetch
> >> >
> >> > Either the doc or the behavior of --name-only needs some adjustment.
> >>
> >> This argues for making "all" imply we need to show the name of the
> >> configuration variable,
> >
> > Sorry can you elaborate on what that "all" meant? A new option "--show-all"?
> 
> Sorry, but "--all" is probably a red herring.
> 
> What I wanted to say was that we can 
> 
>  (1) get rid of "--show-name",
> 
>  (2) have the combination of options that can emit values for more
>     than one key to automatically show both name and value, and
> 
>  (3) add "--hide-name" so that such command can still show only the
>      value.
> 
> where I mixed up (2) and "all".  In fact, "--all" is not something
> that gives values for more than one key (it is things like regexp
> and urlmatch).

I wouldn't get rid of `--show-name`, as it also implicitly brings along `--no-show-name`, basically checking the box for (3).

In any case, I agree that it probably makes sense to do (2). Unless I'm mistaken, the only case we need to care about is `--regexp`, because without all the emitted names would be the same anyway.

Patrick
Junio C Hamano· Aug 22, 2024, 14:54 UTC · re: Patrick Steinhardt · lore

Re: builtin/config: --name-only doesn't imply --show-names in "git config get"

Patrick Steinhardt <ps@pks.im> writes:
> In any case, I agree that it probably makes sense to do (2). Unless I'm
> mistaken, the only case we need to care about is `--regexp`, because
> without all the emitted names would be the same anyway.

OK. And we need to fix the "config --get-all" description, which does not need --show-names there, I think.

Thanks.

← back to recent threads