From: Cord Seele Date: Fri, 30 Sep 2011 10:52:24 +0000 (+0200) Subject: Add Git::config_path() X-Git-Tag: v1.7.8-rc0~12^2~3 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=9fef9e279055423363e110b7246a9b8bbcf0bd72;p=git.git Add Git::config_path() Use --path option when calling 'git config' thus allow for pathname expansion, e.g. a tilde. Signed-off-by: Cord Seele Signed-off-by: Junio C Hamano --- diff --git a/perl/Git.pm b/perl/Git.pm index a86ab709c..c279bfb24 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -627,6 +627,38 @@ sub config_bool { }; } + +=item config_path ( VARIABLE ) + +Retrieve the path configuration C. The return value +is an expanded path or C if it's not defined. + +This currently wraps command('config') so it is not so fast. + +=cut + +sub config_path { + my ($self, $var) = _maybe_self(@_); + + try { + my @cmd = ('config', '--path'); + unshift @cmd, $self if $self; + if (wantarray) { + return command(@cmd, '--get-all', $var); + } else { + return command_oneline(@cmd, '--get', $var); + } + } catch Git::Error::Command with { + my $E = shift; + if ($E->value() == 1) { + # Key not found. + return undef; + } else { + throw $E; + } + }; +} + =item config_int ( VARIABLE ) Retrieve the integer configuration C. The return value