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

Re: [PATCH] perl: add new module Git::Config for cached 'git config' access

From
SVSam Vilain <samv@catalyst.net.nz>
Date
Apr 8, 2009, 10:44 UTC
Message-ID
<49DC8002.6050503@catalyst.net.nz>
In-Reply-To
<200904081218.39984.jnareb@gmail.com>
Jakub Narebski wrote:
> By the way, did you take a look how cached 'git config' access and
> typecasting is done in gitweb?  See commit b201927 (gitweb: Read
> repo config using 'git config -z -l') and following similar commits.
>   

Right ... sure, looks fairly straightforward. I guess gitweb could potentially use this tested module instead of including that code itself. Also various parts of git-svn... anything really.

I actually wrote this code because I wanted something a bit nicer for writing the mirror-sync initial implementations. And I wanted to have a bit of control over when values get committed, and save work for reading, so I wrote this.

Show 9 quoted lines
>> Any more gremlins? 
>>     
> I have nor examined your patch in detail; I'll try to do it soon,
> but with git config file parsing there lies following traps.
>
> 1. In fully qualified variable name section name and variable name
>    have to be compared case insensitive (or normalized, i.e.
>    lowercased), while subsection part (if it exists) is case sensitive.
>   

I noticed that 'git config' hides this by normalising the case of what it outputs with 'git config --list'; do you think anything special is required in light of this?

Show 5 quoted lines
> 2. When coercing type to bool, you need to remember (and test) that
>    there are values which are truish (no value, 'true', 'yes', non-zero
>    integer usually 1), values which are falsish (empry, 'false', 'no',
>    0); other values IIRC are truish too.
>   

Yep, see the Git::Config::boolean mini-package which has a list of those. I think I used the documented legal values, which are 'true', 'yes' and '1' for affirmative and 'false', 'no' and '0' for negative. I guess I could make that include non-zero integers as well.

> 3. When coercing type to int, you need to remember about optional
>    value suffixes: 'k', 'm' or 'g'.
>   

Yep, covered on input and output :-). See Git::Config::integer for the conversion functions.

> 4. I don't know if you remembered about 'colorbool' and 'color'; the
>    latter would probably require some extra CPAN module for ANSI color
>    escapes... or copying color codes from the C version.
>   

Yeah, I thought those could probably be done with a follow-up patch. It's just a matter of writing functions Git::Config::color::thaw and ::freeze.

> Why not represent it simply as an 'undef'? You can always distinguish 
> between not defined and not existing by using 'exists'...
>   

I don't like 'undef' being a data value. In this case I was already using setting a value to undef to tell the module to remove the key from the config file. But in any case you should not need to care what form the values exist in the internal ->{read_state} hash, as you should always be retrieving them using the ->config method, which will marshall them into the type you want. Note it's always the same object, just like Perl's &PL_undef via the C API.

Show 5 quoted lines
>> Sneak a couple of vim footer changes in too.
>>     
>
> Hmmm...
>   
Guess someone noticed them.  Oh well, rebase time ...
Thanks for your input Jakub, I'll incorporate your suggestions.
Sam
Previous: Jakub NarebskiNext: Jakub Narebski
Message 8 of 13 in “perl: add new module Git::Config for cached 'git config' access”
  1. perl: add new module Git::Config for cached 'git config' accessSam Vilain, Apr 5, 2009
  2. perl: make Git.pm use new Git::Config moduleSam Vilain, Apr 5, 2009
  3. Frank LichtenheldApr 6, 2009
  4. Sam VilainApr 6, 2009
  5. Jakub NarebskiApr 7, 2009
  6. Sam VilainApr 8, 2009
  7. Jakub NarebskiApr 8, 2009
  8. Sam VilainApr 8, 2009
  9. Jakub NarebskiApr 8, 2009
  10. Junio C HamanoApr 8, 2009
  11. Sam VilainApr 8, 2009
  12. Junio C HamanoApr 8, 2009
  13. Petr BaudisApr 8, 2009

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.