From: Sam Vilain <sam.vilain@catalyst.net.nz>
To: Frank Lichtenheld <frank@lichtenheld.de>
Cc: git@vger.kernel.org, Petr Baudis <pasky@suse.cz>
Subject: Re: [PATCH] perl: add new module Git::Config for cached 'git config' access
Date: Tue, 07 Apr 2009 10:50:59 +1200 [thread overview]
Message-ID: <1239058276.31863.19.camel@maia.lan> (raw)
In-Reply-To: <20090406092942.GW17706@mail-vs.djpig.de>
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:
> > + 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>
---
perl/Git/Config.pm | 6 ++++--
t/t9700/config.t | 4 ++++
2 files changed, 8 insertions(+), 2 deletions(-)
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;
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");
@@ -92,6 +93,9 @@ in_empty_repo sub {
is($unset, undef,
"boolean thaw - not present");
+ like($conf->config("multiline.val"), qr{\n},
+ "parsing multi-line values");
+
$git->command_oneline("config", "foo.intval", "12g");
$git->command_oneline("config", "foo.falseval", "false");
$git->command_oneline("config", "foo.trueval", "on");
--
debian.1.5.6.1
next prev parent reply other threads:[~2009-04-06 23:01 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-05 23:46 [PATCH] perl: add new module Git::Config for cached 'git config' access Sam Vilain
2009-04-05 23:46 ` [PATCH] perl: make Git.pm use new Git::Config module Sam Vilain
2009-04-06 9:29 ` [PATCH] perl: add new module Git::Config for cached 'git config' access Frank Lichtenheld
2009-04-06 22:50 ` Sam Vilain [this message]
2009-04-07 12:01 ` Jakub Narebski
2009-04-08 5:49 ` Sam Vilain
2009-04-08 10:18 ` Jakub Narebski
2009-04-08 10:44 ` Sam Vilain
2009-04-08 23:13 ` Jakub Narebski
2009-04-08 6:29 ` Junio C Hamano
2009-04-08 9:50 ` Sam Vilain
2009-04-08 18:51 ` Junio C Hamano
2009-04-08 8:12 ` Petr Baudis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1239058276.31863.19.camel@maia.lan \
--to=sam.vilain@catalyst.net.nz \
--cc=frank@lichtenheld.de \
--cc=git@vger.kernel.org \
--cc=pasky@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).