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

Re: [PATCH/RFC] Hacky version of a glob() driven config include

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
May 7, 2010, 22:15 UTC
Message-ID
<AANLkTinCaPrThtuQd7tUFxNNn9KUx9v3_PXnH_6C8yco@mail.gmail.com>
In-Reply-To
<m3k4rfe90n.fsf@localhost.localdomain>
On Fri, May 7, 2010 at 20:46, Jakub Narebski <jnareb@gmail.com> wrote:
Show 6 quoted lines
> Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
>
>> This is not ready for inclusion in anything. Commiting for RFC on
>> whether this way of doing it is sane in theory.
>
> I think this is a good idea at least in theory.
Thanks, and thanks for all your comments below. They were very useful.
Show 10 quoted lines
>> Known bugs:
>>
>>   * Breaks the model of being able to *set* config values. That
>>     doesn't work for the included files. Maybe not a bug.
>
> Errr... do I understand correctly that it simply means that you are
> not able to set config values that came from included files, in
> included files?
>
> This is quite serious limitation.

It is. And recap, you can now you can set Git's config in either places .git/config, ~/.gitconfig and $prefix/etc/gitconfig.

With inclusion this is a bit more complex. If my ~/.gitconfig includes a seekrt.key=foobar via an include in ~/.gitconfig/seekrt, what should `git config --global seekrt.key newkey` do? How about `git config --global seekrt.some_new_value blah`?

I think it's best to not try to get into that mess and just let the user manage included files manually, or with `git config --file`.

Show 12 quoted lines
>>   * Errors in the git_config_from_file() call in glob_include_config()
>>     aren't passed upwards.
>
> Hmmm...
>
>>
>>   * It relies on the GNU GLOB_TILDE extension with no
>>     alternative. That can be done by calling getenv("HOME") and
>>     s/~/$home/.
>
> "git config --path <variable>" expands leading '~' to $HOME, and ~user
> to home directory of given user.  Why not use this?

I didn't spot it. expand_user_path() does do everything I need, yippie! I'll use that then.

Show 6 quoted lines
>>   * The whole bit with saving/restoring global state for config
>>     inclusion is evil, but then again so is the global state.
>
> Why not encapsulate those global variables in a struct, passed to
> appropriate functions, with a global variable holding an instance of
> such struct (IIRC similarly to what is done for "the_index").

That's indeed the sane way to go. I'll do that (and look at the_index).

Show 6 quoted lines
>>   * We don't check for recursion. But Git gives up eventually after
>>     after spewing a *lot* of duplicate entry errors. Not sure how to
>>     do this sanely w/symlinks.
>
> The alternates mechanism has some depth limit; why not use it also for
> config file inclusion?  The machanism is quite similar...

Yet another example of prior art in git itself I have to check out, thanks.

Show 21 quoted lines
>> Not-signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
>
> You can simply do not add Signed-off-by for an RFC patch...
>
>> ---
>>
>> > On Sun, Apr 4, 2010 at 07:50, Eli Barzilay <eli@barzilay.org> wrote:
>> > > Isn't it better to have a way to include files instead?
>> >
>> > Probably yes. Programs like Apache HTTPD, rsyslog and others just use
>> > ${foo}conf.d by convention by supporting config inclusion.
>>
>> Here's an evil implementation of this. I know the code is horrid &
>> buggy (see above). But is the general idea sane. I thought it would be
>> better to submit this for comments before I went further with it.
>>
>>  config.c               |   55 +++++++++++++++++++++++++++++++++++++++++++++++-
>>  t/t1300-repo-config.sh |   43 +++++++++++++++++++++++++++++++++++++
>>  2 files changed, 97 insertions(+), 1 deletions(-)
>
> No documentation.

A final patch will have that. Since some of the semantics are "munges your .gitconfig" (a bug). I'll write dosc for it once it's behaving.

Show 17 quoted lines
> [...]
>> diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh
>> index f11f98c..4df6658 100755
>> --- a/t/t1300-repo-config.sh
>> +++ b/t/t1300-repo-config.sh
>> @@ -824,4 +824,47 @@ test_expect_success 'check split_cmdline return' "
>>       test_must_fail git merge master
>>       "
>>
>> +cat > .git/config << EOF
>> +[some]
>> +     variable = blah
>> +[voodoo]
>> +     include = .git/more_config_*
>> +EOF
>
> I don't like this syntax.
Me neither.
> First, it forces git-config to hide all 'include' keys.  I think there
> might be some legitimate <section>.include config variables (perhaps
> outside git-core); with this patch they are impossible.

It's only hiding the full 'voodoo.include' key currently, you can still have e.g. 'bleh.include'.

Show 8 quoted lines
> Second, I guess that the section name has absolutely no meaning here.
> If included config file has section.key config variable, i.e.:
>
>  [section]
>        key = value
>
> the variable in master config file (visible by git-config) would not
> be voodoo.section.key.

No. All includes are done at the top level. The end result should be equivalent to having used cat(1) to stitch a bunch of config files together.

Show 16 quoted lines
> Third, what happens with the sections in master config file?  If I
> have the following in .git/config
>
>  [voodoo]
>        var1 = val1
>        include = .git/more_config
>        var2 = val2
>
> and the .git/more_config has
>
>  [foo]
>        bar = baz
>
> would "git config --list" see 'voodoo.var2' (i.e. sections in included
> file does not change parsing of master file), or would it see
> 'foo.var2'?

Only voodoo.include should be hidden, nothing else. But let's move on to..

Show 5 quoted lines
> I would propose
>
>  include .git/more_config_*
>
> if not for the fast that it would trip older git.  Perhaps
>  ## include ".git/more_config_*"

Probably not a good idea to mix up comments & configuration like that. Some (semi-broken) parsers of .gitconfig also use INI parsers to parse it, which breaks on # comments. Those are already broken, but it would be nice if a feature didn't require them.

>  [include .git/more_config_*]
Syntax error on older Gits.
>  [include ".git/more_config_*"]

I like this one the best. It's also easy to modify the parser (so it doesn't think it's a section) to handle it. And it doesn't incur the confusion of looking like a normal configuration variable.

Previous: Jakub NarebskiNext: Jakub Narebski
Message 16 of 21 in “Is there interest in reading ~/.gitconfig.d/* and /etc/gitconfig.d/*?”
  1. Ævar Arnfjörð BjarmasonApr 1, 2010
  2. Heiko VoigtApr 1, 2010
  3. Peter KreftingApr 4, 2010
  4. Eli BarzilayApr 4, 2010
  5. Ævar Arnfjörð BjarmasonApr 6, 2010
  6. Jakub NarebskiApr 6, 2010
  7. Hacky version of a glob() driven config includeÆvar Arnfjörð Bjarmason, May 6, 2010
  8. Bert WesargMay 7, 2010
  9. Ævar Arnfjörð BjarmasonMay 7, 2010
  10. Bert WesargMay 7, 2010
  11. Ævar Arnfjörð BjarmasonMay 7, 2010
  12. Jacob HelwigMay 7, 2010
  13. Bert WesargMay 7, 2010
  14. Hacky version of a glob() driven config includeÆvar Arnfjörð Bjarmason, May 7, 2010
  15. Jakub NarebskiMay 7, 2010
  16. Ævar Arnfjörð BjarmasonMay 7, 2010
  17. Jakub NarebskiMay 7, 2010
  18. Ping YinMay 8, 2010
  19. Jakub NarebskiMay 8, 2010
  20. Ping YinMay 8, 2010
  21. Jeff KingMay 8, 2010

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.