diff options
author | Petr Baudis <pasky@suse.cz> | 2006-07-03 22:47:55 +0200 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2006-07-03 18:35:19 -0700 |
commit | dc2613de8633cecb1c0759657eadf6a637cebfa5 (patch) | |
tree | 2921e9bca0645ac65dd9c8a3207e6d395bca9e8e /perl | |
parent | 6fcca938b05c33bcd8b502d6b6f178e377609fa3 (diff) | |
download | git-dc2613de8633cecb1c0759657eadf6a637cebfa5.tar.gz |
Git.pm: Add config() method
This accessor will retrieve value(s) of the given configuration variable.
Signed-off-by: Petr Baudis <pasky@suse.cz>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'perl')
-rw-r--r-- | perl/Git.pm | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/perl/Git.pm b/perl/Git.pm index b4ee88bdfd..24fd7ce25c 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -473,7 +473,6 @@ and the directory must exist. sub wc_chdir { my ($self, $subdir) = @_; - $self->wc_path() or throw Error::Simple("bare repository"); @@ -486,6 +485,42 @@ sub wc_chdir { } +=item config ( VARIABLE ) + +Retrieve the configuration C<VARIABLE> in the same manner as C<repo-config> +does. In scalar context requires the variable to be set only one time +(exception is thrown otherwise), in array context returns allows the +variable to be set multiple times and returns all the values. + +Must be called on a repository instance. + +This currently wraps command('repo-config') so it is not so fast. + +=cut + +sub config { + my ($self, $var) = @_; + $self->repo_path() + or throw Error::Simple("not a repository"); + + try { + if (wantarray) { + return $self->command('repo-config', '--get-all', $var); + } else { + return $self->command_oneline('repo-config', '--get', $var); + } + } catch Git::Error::Command with { + my $E = shift; + if ($E->value() == 1) { + # Key not found. + return undef; + } else { + throw $E; + } + }; +} + + =item hash_object ( TYPE, FILENAME ) =item hash_object ( TYPE, FILEHANDLE ) |