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>
Jakub Narebski committed
Nov 23, 2007 at 19:04 UTC
346d203bc3931c33f2e40093ee9325ab0334b9fe
1 file changed
+31
perl/Git.pm
+31
@@ -549,6 +549,37 @@ sub config_bool {
549
};
550
}
551
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
+}
583
584
=item ident ( TYPE | IDENTSTR )
585