@@ -487,22 +487,20 @@ does. In scalar context requires the variable to be set only one time
487
487
(exception is thrown otherwise), in array context returns allows the
488
488
variable to be set multiple times and returns all the values.
489
489
490
- Must be called on a repository instance.
491
-
492
490
This currently wraps command('config') so it is not so fast.
493
491
494
492
=cut
495
493
496
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(@_ );
500
496
501
497
try {
498
+ my @cmd = (' config' );
499
+ unshift @cmd , $self if $self ;
502
500
if (wantarray ) {
503
- return $self -> command(' config ' , ' --get-all' , $var );
501
+ return command(@cmd , ' --get-all' , $var );
504
502
} else {
505
- return $self -> command_oneline(' config ' , ' --get' , $var );
503
+ return command_oneline(@cmd , ' --get' , $var );
506
504
}
507
505
} catch Git::Error::Command with {
508
506
my $E = shift ;
@@ -522,20 +520,17 @@ Retrieve the bool configuration C<VARIABLE>. The return value
522
520
is usable as a boolean in perl (and C<undef > if it's not defined,
523
521
of course).
524
522
525
- Must be called on a repository instance.
526
-
527
523
This currently wraps command('config') so it is not so fast.
528
524
529
525
=cut
530
526
531
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(@_ );
535
529
536
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 );
539
534
return undef unless defined $val ;
540
535
return $val eq ' true' ;
541
536
} catch Git::Error::Command with {
@@ -557,19 +552,17 @@ or 'g' in the config file will cause the value to be multiplied
557
552
by 1024, 1048576 (1024^2), or 1073741824 (1024^3) prior to output.
558
553
It would return C<undef > if configuration variable is not defined,
559
554
560
- Must be called on a repository instance.
561
-
562
555
This currently wraps command('config') so it is not so fast.
563
556
564
557
=cut
565
558
566
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(@_ );
570
561
571
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 );
573
566
} catch Git::Error::Command with {
574
567
my $E = shift ;
575
568
if ($E -> value() == 1) {
@@ -639,15 +632,15 @@ The synopsis is like:
639
632
"$name <$email>" eq ident_person($name);
640
633
$time_tz =~ /^\d+ [+-]\d{4}$/;
641
634
642
- Both methods must be called on a repository instance.
643
-
644
635
=cut
645
636
646
637
sub ident {
647
- my ($self , $type ) = @_ ;
638
+ my ($self , $type ) = _maybe_self( @_ ) ;
648
639
my $identstr ;
649
640
if (lc $type eq lc ' committer' or lc $type eq lc ' author' ) {
650
- $identstr = $self -> command_oneline(' var' , ' GIT_' .uc ($type ).' _IDENT' );
641
+ my @cmd = (' var' , ' GIT_' .uc ($type ).' _IDENT' );
642
+ unshift @cmd , $self if $self ;
643
+ $identstr = command_oneline(@cmd );
651
644
} else {
652
645
$identstr = $type ;
653
646
}
@@ -659,8 +652,8 @@ sub ident {
659
652
}
660
653
661
654
sub ident_person {
662
- my ($self , @ident ) = @_ ;
663
- $#ident == 0 and @ident = $self -> ident($ident [0]);
655
+ my ($self , @ident ) = _maybe_self( @_ ) ;
656
+ $#ident == 0 and @ident = $self ? $self -> ident( $ident [0]) : ident($ident [0]);
664
657
return " $ident [0] <$ident [1]>" ;
665
658
}
666
659
0 commit comments