@matheusbsbs / matheus-bagliano / commits / c2e357c2fe
Fork 0

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>

Frank Lichtenheld committed Mar 14, 2008 at 18:29 UTC c2e357c2fe23ff900de158067ca11e5021e22741
1 file changed +13 -20
perl/Git.pm
+13 -20
@@ -487,22 +487,20 @@ does. In scalar context requires the variable to be set only one time
487 (exception is thrown otherwise), in array context returns allows the
488 variable to be set multiple times and returns all the values.
489
490 -Must be called on a repository instance.
491 -
490 This currently wraps command('config') so it is not so fast.
491
492 =cut
493
494 sub config {
497 - my ($self, $var) = @_;
498 - $self->repo_path()
499 - or throw Error::Simple("not a repository");
495 + my ($self, $var) = _maybe_self(@_);
496
497 try {
498 + my @cmd = ('config');
499 + unshift @cmd, $self if $self;
500 if (wantarray) {
503 - return $self->command('config', '--get-all', $var);
501 + return command(@cmd, '--get-all', $var);
502 } else {
505 - return $self->command_oneline('config', '--get', $var);
503 + return command_oneline(@cmd, '--get', $var);
504 }
505 } catch Git::Error::Command with {
506 my $E = shift;
@@ -522,20 +520,17 @@ Retrieve the bool configuration C<VARIABLE>. The return value
520 is usable as a boolean in perl (and C<undef> if it's not defined,
521 of course).
522
525 -Must be called on a repository instance.
526 -
523 This currently wraps command('config') so it is not so fast.
524
525 =cut
526
527 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(@_);
529
530 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);
534 return undef unless defined $val;
535 return $val eq 'true';
536 } catch Git::Error::Command with {
@@ -557,19 +552,17 @@ or 'g' in the config file will cause the value to be multiplied
552 by 1024, 1048576 (1024^2), or 1073741824 (1024^3) prior to output.
553 It would return C<undef> if configuration variable is not defined,
554
560 -Must be called on a repository instance.
561 -
555 This currently wraps command('config') so it is not so fast.
556
557 =cut
558
559 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(@_);
561
562 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);
566 } catch Git::Error::Command with {
567 my $E = shift;
568 if ($E->value() == 1) {