about summary refs log tree commit homepage
path: root/lib/PublicInbox/Config.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-10-03 06:43:47 +0000
committerEric Wong <e@80x24.org>2023-10-03 10:16:05 +0000
commitd0a8dd236f768965aa9c034975412d526dab8a01 (patch)
tree2812b2965b48a919457c51edaa174869d623747b /lib/PublicInbox/Config.pm
parentf751ae24b9a4595f2feb493a21d2b18c27210688 (diff)
downloadpublic-inbox-d0a8dd236f768965aa9c034975412d526dab8a01.tar.gz
When using --get-urlmatch, we need a way to distinguish between
between key-only or a `key=val' pair even if the `val' is empty.
In other words, git interprets `-c imap.debug' as true and
`-c imap.debug=' as false, but an untyped --get-urlmatch
invocation has no way to distinguish between them.

So we must specify we want `--bool' (we're avoiding `--type=bool'
since that only appears in git 2.18+)

Fixes: f170d220f876 (lei: fix `-c NAME=VALUE' config support)
Diffstat (limited to 'lib/PublicInbox/Config.pm')
-rw-r--r--lib/PublicInbox/Config.pm18
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index 9f764c32..15e0872e 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -568,28 +568,34 @@ sub config_cmd {
 }
 
 sub urlmatch {
-        my ($self, $key, $url, $try_git) = @_;
+        my $self = shift;
+        my @bool = $_[0] eq '--bool' ? (shift) : ();
+        my ($key, $url, $try_git) = @_;
         state $urlmatch_broken; # requires git 1.8.5
         return if $urlmatch_broken;
         my (%env, %opt);
         my $cmd = $self->config_cmd(\%env, \%opt);
-        push @$cmd, qw(-z --includes --get-urlmatch), $key, $url;
+        push @$cmd, @bool, qw(--includes -z --get-urlmatch), $key, $url;
         my $fh = popen_rd($cmd, \%env, \%opt);
         local $/ = "\0";
         my $val = <$fh>;
         if (!close($fh)) {
                 undef $val;
-                if (($? >> 8) != 1) {
+                if (@bool && ($? >> 8) == 128) { # not boolean
+                } elsif (($? >> 8) != 1) {
                         $urlmatch_broken = 1;
                 } elsif ($try_git) { # n.b. this takes cwd into account
-                        $cmd = [qw(git config -z --get-urlmatch), $key, $url];
-                        $fh = popen_rd($cmd);
+                        $fh = popen_rd([qw(git config), @bool,
+                                        qw(-z --get-urlmatch), $key, $url]);
                         $val = <$fh>;
                         close($fh) or undef($val);
                 }
         }
         $? = 0; # don't influence lei exit status
-        chomp $val if defined $val;
+        if (defined($val)) {
+                chomp $val;
+                $val = git_bool($val) if @bool;
+        }
         $val;
 }