[PATCH] Add config_int() method to the Git perl module

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jakub Narebski
Date: Friday, November 23, 2007 - 11:04 am

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>
---
For completness (I don't think anything in Perl uses / tries to use
integer configuration variables).

(Commit message could be better. Hmmm...)

 perl/Git.pm |   31 +++++++++++++++++++++++++++++++
 1 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/perl/Git.pm b/perl/Git.pm
index dca92c8..7468460 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -549,6 +549,37 @@ sub config_bool {
 	};
 }
 
+=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 )
 
-- 
1.5.3.5

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] Add config_int() method to the Git perl module, Jakub Narebski, (Fri Nov 23, 11:04 am)
Re: [PATCH] Add config_int() method to the Git perl module, Junio C Hamano, (Fri Nov 23, 12:59 pm)
Re: [PATCH] Add config_int() method to the Git perl module, Wincent Colaiuta, (Fri Nov 23, 1:57 pm)
[PATCH] git-config --get-color: get configured color, Junio C Hamano, (Wed Nov 28, 12:20 am)