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
Jakub Narebski <jnareb@gmail.com>
Date
Apr 7, 2009, 12:01 UTC
Message-ID
<m3prfo1xh6.fsf@localhost.localdomain>
In-Reply-To
<1239058276.31863.19.camel@maia.lan>
Sam Vilain <sam.vilain@catalyst.net.nz> writes:
> On Mon, 2009-04-06 at 11:29 +0200, Frank Lichtenheld wrote:
> > On Mon, Apr 06, 2009 at 11:46:15AM +1200, Sam Vilain wrote:
Show 17 quoted lines
> > > +	my ($fh, $c) = $git->command_output_pipe(
> > > +		'config', ( $which ? ("--$which") : () ),
> > > +		'--list',
> > > +	       );
> >
> > Any reason why you don't use --null here? The output of --list
> > without --null is not reliably parsable, since people can put
> > newlines in values.
> 
> No particularly good reason :-)
> 
> Subject: [PATCH] perl: make Git::Config use --null
> 
> Use the form of 'git-config' designed for parsing by modules like
> this for safety with values containing embedded line feeds.
> 
> Signed-off-by: Sam Vilain <sam.vilain@catalyst.net.nz>
Show 21 quoted lines
> diff --git a/perl/Git/Config.pm b/perl/Git/Config.pm
> index a0a6a41..a35d9f3 100644
> --- a/perl/Git/Config.pm
> +++ b/perl/Git/Config.pm
> @@ -179,12 +179,14 @@ sub read {
>  
>  	my ($fh, $c) = $git->command_output_pipe(
>  		'config', ( $which ? ("--$which") : () ),
> -		'--list',
> +		 '--null', '--list',
>  	       );
>  	my $read_state = {};
>  
> +	local($/)="\0";
>  	while (<$fh>) {
> -		my ($item, $value) = m{(.*?)=(.*)};
> +		my ($item, $value) = m{(.*?)\n((?s:.*))\0}
> +			or die "failed to parse it; \$_='$_'";
>  		my $sl = \( $read_state->{$item} );
>  		if (!defined $$sl) {
>  			$$sl = $value;
Errr... wouldn't it be better to simply use 
+		my ($item, $value) = split("\n", $_, 2)

here? Have you tested Git::Config with a "null" value, i.e. something like

    [section]
        noval

in the config file (which evaluates to 'true' with '--bool' option)? Because from what I remember from the discussion on the "git config --null --list" format the lack of "\n" is used to distinguish between noval (which is equivalent to 'true'), and empty value (which is equivalent to 'false')

    [boolean
        noval        # equivalent to 'true'
        empty1 =     # equivalent to 'false'
        empty2 = ""  # equivalent to 'false'
Show 12 quoted lines
> diff --git a/t/t9700/config.t b/t/t9700/config.t
> index 395a5c9..f0f7d2d 100644
> --- a/t/t9700/config.t
> +++ b/t/t9700/config.t
> @@ -16,6 +16,7 @@ in_empty_repo sub {
>  	$git->command_oneline("config", "foo.intval", "12g");
>  	$git->command_oneline("config", "foo.false.val", "false");
>  	$git->command_oneline("config", "foo.true.val", "yes");
> +	$git->command_oneline("config", "multiline.val", "hello\nmultiline.val=world");
>  
>  	my $conf = Git::Config->new();
>  	ok($conf, "constructed a new Git::Config");
-- 
Jakub Narebski
Poland
ShadeHawk on #git
Previous: Sam VilainNext: Sam Vilain
Message 5 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.