From: Frank Lichtenheld <frank@lichtenheld.de>
To: Junio C Hamano <junkio@cox.net>
Cc: Git Mailing List <git@vger.kernel.org>,
Frank Lichtenheld <frank@lichtenheld.de>
Subject: [PATCH 2/4] Git.pm: Don't require a repository instance for config
Date: Fri, 14 Mar 2008 18:29:28 +0100 [thread overview]
Message-ID: <1205515770-3424-3-git-send-email-frank@lichtenheld.de> (raw)
In-Reply-To: <1205515770-3424-2-git-send-email-frank@lichtenheld.de>
git config itself doesn't require to be called in a repository,
do don't add arbitrary restrictions.
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.de>
---
perl/Git.pm | 33 +++++++++++++--------------------
1 files changed, 13 insertions(+), 20 deletions(-)
diff --git a/perl/Git.pm b/perl/Git.pm
index a2812ea..67b3749 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -487,22 +487,20 @@ does. In scalar context requires the variable to be set only one time
(exception is thrown otherwise), in array context returns allows the
variable to be set multiple times and returns all the values.
-Must be called on a repository instance.
-
This currently wraps command('config') so it is not so fast.
=cut
sub config {
- my ($self, $var) = @_;
- $self->repo_path()
- or throw Error::Simple("not a repository");
+ my ($self, $var) = _maybe_self(@_);
try {
+ my @cmd = ('config');
+ unshift @cmd, $self if $self;
if (wantarray) {
- return $self->command('config', '--get-all', $var);
+ return command(@cmd, '--get-all', $var);
} else {
- return $self->command_oneline('config', '--get', $var);
+ return command_oneline(@cmd, '--get', $var);
}
} catch Git::Error::Command with {
my $E = shift;
@@ -522,20 +520,17 @@ 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.
-
This currently wraps command('config') so it is not so fast.
=cut
sub config_bool {
- my ($self, $var) = @_;
- $self->repo_path()
- or throw Error::Simple("not a repository");
+ my ($self, $var) = _maybe_self(@_);
try {
- my $val = $self->command_oneline('config', '--bool', '--get',
- $var);
+ my @cmd = ('config', '--bool', '--get', $var);
+ unshift @cmd, $self if $self;
+ my $val = command_oneline(@cmd);
return undef unless defined $val;
return $val eq 'true';
} catch Git::Error::Command with {
@@ -557,19 +552,17 @@ 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");
+ my ($self, $var) = _maybe_self(@_);
try {
- return $self->command_oneline('config', '--int', '--get', $var);
+ my @cmd = ('config', '--int', '--get', $var);
+ unshift @cmd, $self if $self;
+ return command_oneline(@cmd);
} catch Git::Error::Command with {
my $E = shift;
if ($E->value() == 1) {
--
1.5.4.4
next prev parent reply other threads:[~2008-03-14 17:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-14 17:29 [PATCH 0/4] Don't require to be in the repository if we don't need to Frank Lichtenheld
2008-03-14 17:29 ` [PATCH 1/4] var: Don't require to be in a git repository Frank Lichtenheld
2008-03-14 17:29 ` Frank Lichtenheld [this message]
2008-03-14 17:29 ` [PATCH 3/4] Git.pm: Don't require repository instance for ident Frank Lichtenheld
2008-03-14 17:29 ` [PATCH 4/4] send-email: Don't require to be called in a repository Frank Lichtenheld
2008-03-16 3:55 ` [PATCH 0/4] Don't require to be in the repository if we don't need to Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1205515770-3424-3-git-send-email-frank@lichtenheld.de \
--to=frank@lichtenheld.de \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).