summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6fcca93)
raw | patch | inline | side by side (parent: 6fcca93)
author | Petr Baudis <pasky@suse.cz> | |
Mon, 3 Jul 2006 20:47:55 +0000 (22:47 +0200) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Tue, 4 Jul 2006 01:35:19 +0000 (18:35 -0700) |
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>
Signed-off-by: Petr Baudis <pasky@suse.cz>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Documentation/git-repo-config.txt | patch | blob | history | |
perl/Git.pm | patch | blob | history | |
repo-config.c | patch | blob | history |
index 803c0d5cae6db0a953380adc6ee3980a0afa72e0..cc72fa9b74aedd78e82a720e3abcb53bad8b2860 100644 (file)
--get::
Get the value for a given key (optionally filtered by a regex
- matching the value).
+ matching the value). Returns error code 1 if the key was not
+ found and error code 2 if multiple key values were found.
--get-all::
Like get, but does not fail if the number of values for the key
diff --git a/perl/Git.pm b/perl/Git.pm
index b4ee88bdfdc9fd6050b3898d0dcb6040a68ae967..24fd7ce25c20f85cea10fb8ffec1cebf9c38a6af 100644 (file)
--- a/perl/Git.pm
+++ b/perl/Git.pm
sub wc_chdir {
my ($self, $subdir) = @_;
-
$self->wc_path()
or throw Error::Simple("bare repository");
}
+=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 )
diff --git a/repo-config.c b/repo-config.c
index 743f02b7de7b3b819d3db29ddfcdcf8ebacaccc4..c7ed0ac9c95967b45917ab035099257d3e6f0107 100644 (file)
--- a/repo-config.c
+++ b/repo-config.c
if (do_all)
ret = !seen;
else
- ret = (seen == 1) ? 0 : 1;
+ ret = (seen == 1) ? 0 : seen > 1 ? 2 : 1;
free_strings:
if (repo_config)