Skip to content

Commit 35c49ee

Browse files
Petr BaudisJunio C Hamano
authored andcommitted
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 <[email protected]>
1 parent efa615b commit 35c49ee

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

git-remote.perl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,9 @@ sub update_remote {
297297
} elsif ($name eq 'default') {
298298
undef @remotes;
299299
for (sort keys %$remote) {
300-
my $do_fetch = $git->config_boolean("remote." . $_ .
300+
my $do_fetch = $git->config_bool("remote." . $_ .
301301
".skipDefaultUpdate");
302-
if (!defined($do_fetch) || $do_fetch ne "true") {
302+
unless ($do_fetch) {
303303
push @remotes, $_;
304304
}
305305
}

git-send-email.perl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ sub format_2822_time {
154154
$term = new FakeTerm "$@: going non-interactive";
155155
}
156156

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) {
159159
$chain_reply_to = 0;
160160
}
161161

perl/Git.pm

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -516,24 +516,28 @@ sub config {
516516
}
517517

518518

519-
=item config_boolean ( VARIABLE )
519+
=item config_bool ( VARIABLE )
520520
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).
522524
523525
Must be called on a repository instance.
524526
525527
This currently wraps command('config') so it is not so fast.
526528
527529
=cut
528530

529-
sub config_boolean {
531+
sub config_bool {
530532
my ($self, $var) = @_;
531533
$self->repo_path()
532534
or throw Error::Simple("not a repository");
533535

534536
try {
535-
return $self->command_oneline('config', '--bool', '--get',
537+
my $val = $self->command_oneline('config', '--bool', '--get',
536538
$var);
539+
return undef unless defined $val;
540+
return $val eq 'true';
537541
} catch Git::Error::Command with {
538542
my $E = shift;
539543
if ($E->value() == 1) {

0 commit comments

Comments
 (0)