Skip to content

Commit 346d203

Browse files
jnarebgitster
authored andcommitted
Add config_int() method to the Git perl module
Integer variables can have optional 'k', 'm' or 'g' suffix. config_int() method will return simple decimal number, taking care of those suffixes. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent d6617c7 commit 346d203

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

perl/Git.pm

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,37 @@ sub config_bool {
549549
};
550550
}
551551

552+
=item config_int ( VARIABLE )
553+
554+
Retrieve the integer configuration C<VARIABLE>. The return value
555+
is simple decimal number. An optional value suffix of 'k', 'm',
556+
or 'g' in the config file will cause the value to be multiplied
557+
by 1024, 1048576 (1024^2), or 1073741824 (1024^3) prior to output.
558+
It would return C<undef> if configuration variable is not defined,
559+
560+
Must be called on a repository instance.
561+
562+
This currently wraps command('config') so it is not so fast.
563+
564+
=cut
565+
566+
sub config_int {
567+
my ($self, $var) = @_;
568+
$self->repo_path()
569+
or throw Error::Simple("not a repository");
570+
571+
try {
572+
return $self->command_oneline('config', '--int', '--get', $var);
573+
} catch Git::Error::Command with {
574+
my $E = shift;
575+
if ($E->value() == 1) {
576+
# Key not found.
577+
return undef;
578+
} else {
579+
throw $E;
580+
}
581+
};
582+
}
552583

553584
=item ident ( TYPE | IDENTSTR )
554585

0 commit comments

Comments
 (0)