Git.pm: Don't require a repository instance for config
git config itself doesn't require to be called in a repository, so don't add arbitrary restrictions. Signed-off-by: Frank Lichtenheld <frank@lichtenheld.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
2fba8366ed
commit
c2e357c2fe
33
perl/Git.pm
33
perl/Git.pm
@ -487,22 +487,20 @@ does. In scalar context requires the variable to be set only one time
|
|||||||
(exception is thrown otherwise), in array context returns allows the
|
(exception is thrown otherwise), in array context returns allows the
|
||||||
variable to be set multiple times and returns all the values.
|
variable to be set multiple times and returns all the values.
|
||||||
|
|
||||||
Must be called on a repository instance.
|
|
||||||
|
|
||||||
This currently wraps command('config') so it is not so fast.
|
This currently wraps command('config') so it is not so fast.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub config {
|
sub config {
|
||||||
my ($self, $var) = @_;
|
my ($self, $var) = _maybe_self(@_);
|
||||||
$self->repo_path()
|
|
||||||
or throw Error::Simple("not a repository");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
my @cmd = ('config');
|
||||||
|
unshift @cmd, $self if $self;
|
||||||
if (wantarray) {
|
if (wantarray) {
|
||||||
return $self->command('config', '--get-all', $var);
|
return command(@cmd, '--get-all', $var);
|
||||||
} else {
|
} else {
|
||||||
return $self->command_oneline('config', '--get', $var);
|
return command_oneline(@cmd, '--get', $var);
|
||||||
}
|
}
|
||||||
} catch Git::Error::Command with {
|
} catch Git::Error::Command with {
|
||||||
my $E = shift;
|
my $E = shift;
|
||||||
@ -522,20 +520,17 @@ Retrieve the bool configuration C<VARIABLE>. The return value
|
|||||||
is usable as a boolean in perl (and C<undef> if it's not defined,
|
is usable as a boolean in perl (and C<undef> if it's not defined,
|
||||||
of course).
|
of course).
|
||||||
|
|
||||||
Must be called on a repository instance.
|
|
||||||
|
|
||||||
This currently wraps command('config') so it is not so fast.
|
This currently wraps command('config') so it is not so fast.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub config_bool {
|
sub config_bool {
|
||||||
my ($self, $var) = @_;
|
my ($self, $var) = _maybe_self(@_);
|
||||||
$self->repo_path()
|
|
||||||
or throw Error::Simple("not a repository");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
my $val = $self->command_oneline('config', '--bool', '--get',
|
my @cmd = ('config', '--bool', '--get', $var);
|
||||||
$var);
|
unshift @cmd, $self if $self;
|
||||||
|
my $val = command_oneline(@cmd);
|
||||||
return undef unless defined $val;
|
return undef unless defined $val;
|
||||||
return $val eq 'true';
|
return $val eq 'true';
|
||||||
} catch Git::Error::Command with {
|
} catch Git::Error::Command with {
|
||||||
@ -557,19 +552,17 @@ or 'g' in the config file will cause the value to be multiplied
|
|||||||
by 1024, 1048576 (1024^2), or 1073741824 (1024^3) prior to output.
|
by 1024, 1048576 (1024^2), or 1073741824 (1024^3) prior to output.
|
||||||
It would return C<undef> if configuration variable is not defined,
|
It would return C<undef> if configuration variable is not defined,
|
||||||
|
|
||||||
Must be called on a repository instance.
|
|
||||||
|
|
||||||
This currently wraps command('config') so it is not so fast.
|
This currently wraps command('config') so it is not so fast.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub config_int {
|
sub config_int {
|
||||||
my ($self, $var) = @_;
|
my ($self, $var) = _maybe_self(@_);
|
||||||
$self->repo_path()
|
|
||||||
or throw Error::Simple("not a repository");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return $self->command_oneline('config', '--int', '--get', $var);
|
my @cmd = ('config', '--int', '--get', $var);
|
||||||
|
unshift @cmd, $self if $self;
|
||||||
|
return command_oneline(@cmd);
|
||||||
} catch Git::Error::Command with {
|
} catch Git::Error::Command with {
|
||||||
my $E = shift;
|
my $E = shift;
|
||||||
if ($E->value() == 1) {
|
if ($E->value() == 1) {
|
||||||
|
Reference in New Issue
Block a user