Git.pm: config_boolean() -> config_bool()
This patch renames config_boolean() to config_bool() for consistency with the commandline interface and because it is shorter but still obvious. ;-) It also changes the return value from some obscure string to real Perl boolean, allowing for clean user code. Signed-off-by: Petr Baudis <pasky@suse.cz>
Petr Baudis committed
May 9, 2007 at 12:49 UTC
35c49eeae7e71e8554f27958a16405397c69b552
3 files changed
+12
-8
git-remote.perl
+2
-2
@@ -297,9 +297,9 @@ sub update_remote {
297
} elsif ($name eq 'default') {
298
undef @remotes;
299
for (sort keys %$remote) {
300
- my $do_fetch = $git->config_boolean("remote." . $_ .
300
+ my $do_fetch = $git->config_bool("remote." . $_ .
301
".skipDefaultUpdate");
302
- if (!defined($do_fetch) || $do_fetch ne "true") {
302
+ unless ($do_fetch) {
303
push @remotes, $_;
304
}
305
}
git-send-email.perl
+2
-2
@@ -154,8 +154,8 @@ if ($@) {
154
$term = new FakeTerm "$@: going non-interactive";
155
}
156
157
-my $def_chain = $repo->config_boolean('sendemail.chainreplyto');
158
-if ($def_chain and $def_chain eq 'false') {
157
+my $def_chain = $repo->config_bool('sendemail.chainreplyto');
158
+if (defined $def_chain and not $def_chain) {
159
$chain_reply_to = 0;
160
}
161
perl/Git.pm
+8
-4
@@ -516,9 +516,11 @@ sub config {
516
}
517
518
519
-=item config_boolean ( VARIABLE )
519
+=item config_bool ( VARIABLE )
520
521
-Retrieve the boolean configuration C<VARIABLE>.
521
+Retrieve the bool configuration C<VARIABLE>. The return value
522
+is usable as a boolean in perl (and C<undef> if it's not defined,
523
+of course).
524
525
Must be called on a repository instance.
526
@@ -526,14 +528,16 @@ This currently wraps command('config') so it is not so fast.
528
529
=cut
530
529
-sub config_boolean {
531
+sub config_bool {
532
my ($self, $var) = @_;
533
$self->repo_path()
534
or throw Error::Simple("not a repository");
535
536
try {
535
- return $self->command_oneline('config', '--bool', '--get',
537
+ my $val = $self->command_oneline('config', '--bool', '--get',
538
$var);
539
+ return undef unless defined $val;
540
+ return $val eq 'true';
541
} catch Git::Error::Command with {
542
my $E = shift;
543
if ($E->value() == 1) {