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

Re: [RFC/PATCH (WIP)] Git.pm: Add get_config() method and related subroutines

From
LWLea Wiemann <lewiemann@gmail.com>
Date
Jul 3, 2008, 20:30 UTC
Message-ID
<486D36CB.3090400@gmail.com>
In-Reply-To
<200807031824.55958.jnareb@gmail.com>
Jakub Narebski wrote:
> Add get_config([PREFIX]) method [...]
>
> I hope I am not repeating [Lea's] work.

No, you're not. (You could've checked my repo at <http://repo.or.cz/w/git/gitweb-caching.git> ;-).)

FWIW, I don't think it'll make much of a difference for gitweb, since the 'git config -l' output is cached anyway, but it's good someone's extracting this. Do you have any user for that function besides gitweb?

>  * Should config_val_to_bool and config_val_to_int throw error or
>    just return 'undef' on invalid values?

I suspect that if you have, say, command line tools, throwing an error is better UI behavior than silently ignoring the entry. And developers can always catch errors if they want to.

>  * Is "return wantarray ? %config : \%config;" DWIM-mery good style?
Gitweb uses it as well, and it seems reasonable IMVHO.
>  * Should ->get_config() use ->command_output_pipe, or simpler
>    ->command() method, reading whole config into array?

Does it make a difference? If you're worried about performance, config files are so short that it won't matter; use the easier path.

>  * What should ->get_config() method be named? ->get_config()
>    or perhaps ->config_hash(), or ->config_hashref()?

Regarding the method naming, how about making this an object oriented interface? Bless the hash, and allow calls like $config_hash->get('key'). I'm not sure how to name the constructor, but if you can wait a week or so, you could maybe integrate this into the Git::Repo interface (under Git/Config.pm), so you'd end up with ...

    Git::Repo->new(directory => 'repo.git')->config->get('key')

... where config() transparently parses the config file if it hasn't been read already. (The Git.pm API admittedly seems a little messy -- I'll post about that later -- so adding it to Git::Repo might be better indeed.)

>  * What should ->get_config() have as an optional parameter:
>    PREFIX (/^$prefix/o), or simply SECTION (/^(?:$section)\./o)?

Off the top of my head, I don't see much need for a prefix parameter, so I'd go for 'section'.

I haven't been able to answer all of the questions, but I hope this helps.
-- Lea
Previous: Jakub NarebskiNext: Jakub Narebski
Message 2 of 12 in “Git.pm: Add get_config() method and related subroutines”
  1. Git.pm: Add get_config() method and related subroutinesJakub Narebski, Jul 3, 2008
  2. Lea WiemannJul 3, 2008
  3. Jakub NarebskiJul 3, 2008
  4. Lea WiemannJul 7, 2008
  5. Petr BaudisJul 9, 2008
  6. Petr BaudisJul 9, 2008
  7. Jakub NarebskiJul 9, 2008
  8. Petr BaudisJul 12, 2008
  9. Jakub NarebskiJul 12, 2008
  10. Petr BaudisJul 12, 2008
  11. Jakub NarebskiJul 12, 2008
  12. Petr BaudisJul 12, 2008

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.