Code

Merge branch 'maint'
[git.git] / perl / Git.pm
index b5b1cf5edcd860e88c461c600d3fa841654fef76..7468460f9a6d29d5c4bf14db4921bf28e23b6814 100644 (file)
@@ -516,9 +516,11 @@ sub config {
 }
 
 
-=item config_boolean ( VARIABLE )
+=item config_bool ( VARIABLE )
 
-Retrieve the boolean configuration C<VARIABLE>.
+Retrieve the bool configuration C<VARIABLE>. The return value
+is usable as a boolean in perl (and C<undef> if it's not defined,
+of course).
 
 Must be called on a repository instance.
 
@@ -526,14 +528,16 @@ This currently wraps command('config') so it is not so fast.
 
 =cut
 
-sub config_boolean {
+sub config_bool {
        my ($self, $var) = @_;
        $self->repo_path()
                or throw Error::Simple("not a repository");
 
        try {
-               return $self->command_oneline('config', '--bool', '--get',
+               my $val = $self->command_oneline('config', '--bool', '--get',
                                              $var);
+               return undef unless defined $val;
+               return $val eq 'true';
        } catch Git::Error::Command with {
                my $E = shift;
                if ($E->value() == 1) {
@@ -545,6 +549,37 @@ sub config_boolean {
        };
 }
 
+=item config_int ( VARIABLE )
+
+Retrieve the integer configuration C<VARIABLE>. The return value
+is simple decimal number.  An optional value suffix of 'k', 'm',
+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.
+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.
+
+=cut
+
+sub config_int {
+       my ($self, $var) = @_;
+       $self->repo_path()
+               or throw Error::Simple("not a repository");
+
+       try {
+               return $self->command_oneline('config', '--int', '--get', $var);
+       } catch Git::Error::Command with {
+               my $E = shift;
+               if ($E->value() == 1) {
+                       # Key not found.
+                       return undef;
+               } else {
+                       throw $E;
+               }
+       };
+}
 
 =item ident ( TYPE | IDENTSTR )
 
@@ -808,7 +843,7 @@ sub _cmd_exec {
                $self->wc_subdir() and chdir($self->wc_subdir());
        }
        _execv_git_cmd(@args);
-       die "exec failed: $!";
+       die qq[exec "@args" failed: $!];
 }
 
 # Execute the given Git command ($_[0]) with arguments ($_[1..])
@@ -856,7 +891,13 @@ sub READLINE {
        if ($self->{i} >= scalar @{$self->{data}}) {
                return undef;
        }
-       return $self->{'data'}->[ $self->{i}++ ];
+       my $i = $self->{i};
+       if (wantarray) {
+               $self->{i} = $#{$self->{'data'}} + 1;
+               return splice(@{$self->{'data'}}, $i);
+       }
+       $self->{i} = $i + 1;
+       return $self->{'data'}->[ $i ];
 }
 
 sub CLOSE {