Skip to content

Commit c2e357c

Browse files
flichtenheldgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2fba836 commit c2e357c

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

perl/Git.pm

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -487,22 +487,20 @@ does. In scalar context requires the variable to be set only one time
487487
(exception is thrown otherwise), in array context returns allows the
488488
variable to be set multiple times and returns all the values.
489489
490-
Must be called on a repository instance.
491-
492490
This currently wraps command('config') so it is not so fast.
493491
494492
=cut
495493

496494
sub config {
497-
my ($self, $var) = @_;
498-
$self->repo_path()
499-
or throw Error::Simple("not a repository");
495+
my ($self, $var) = _maybe_self(@_);
500496

501497
try {
498+
my @cmd = ('config');
499+
unshift @cmd, $self if $self;
502500
if (wantarray) {
503-
return $self->command('config', '--get-all', $var);
501+
return command(@cmd, '--get-all', $var);
504502
} else {
505-
return $self->command_oneline('config', '--get', $var);
503+
return command_oneline(@cmd, '--get', $var);
506504
}
507505
} catch Git::Error::Command with {
508506
my $E = shift;
@@ -522,20 +520,17 @@ Retrieve the bool configuration C<VARIABLE>. The return value
522520
is usable as a boolean in perl (and C<undef> if it's not defined,
523521
of course).
524522
525-
Must be called on a repository instance.
526-
527523
This currently wraps command('config') so it is not so fast.
528524
529525
=cut
530526

531527
sub config_bool {
532-
my ($self, $var) = @_;
533-
$self->repo_path()
534-
or throw Error::Simple("not a repository");
528+
my ($self, $var) = _maybe_self(@_);
535529

536530
try {
537-
my $val = $self->command_oneline('config', '--bool', '--get',
538-
$var);
531+
my @cmd = ('config', '--bool', '--get', $var);
532+
unshift @cmd, $self if $self;
533+
my $val = command_oneline(@cmd);
539534
return undef unless defined $val;
540535
return $val eq 'true';
541536
} catch Git::Error::Command with {
@@ -557,19 +552,17 @@ or 'g' in the config file will cause the value to be multiplied
557552
by 1024, 1048576 (1024^2), or 1073741824 (1024^3) prior to output.
558553
It would return C<undef> if configuration variable is not defined,
559554
560-
Must be called on a repository instance.
561-
562555
This currently wraps command('config') so it is not so fast.
563556
564557
=cut
565558

566559
sub config_int {
567-
my ($self, $var) = @_;
568-
$self->repo_path()
569-
or throw Error::Simple("not a repository");
560+
my ($self, $var) = _maybe_self(@_);
570561

571562
try {
572-
return $self->command_oneline('config', '--int', '--get', $var);
563+
my @cmd = ('config', '--int', '--get', $var);
564+
unshift @cmd, $self if $self;
565+
return command_oneline(@cmd);
573566
} catch Git::Error::Command with {
574567
my $E = shift;
575568
if ($E->value() == 1) {

0 commit comments

Comments
 (0)