From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 3/8] config: fix key-only truthy values with urlmatch
Date: Tue, 3 Oct 2023 06:43:47 +0000 [thread overview]
Message-ID: <20231003064352.2902298-4-e@80x24.org> (raw)
In-Reply-To: <20231003064352.2902298-1-e@80x24.org>
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)
---
lib/PublicInbox/Config.pm | 18 ++++++++++++------
lib/PublicInbox/NetReader.pm | 18 +++++-------------
t/imapd-tls.t | 4 +++-
t/nntpd-tls.t | 4 +++-
4 files changed, 23 insertions(+), 21 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;
}
diff --git a/lib/PublicInbox/NetReader.pm b/lib/PublicInbox/NetReader.pm
index e14b5805..5819f210 100644
--- a/lib/PublicInbox/NetReader.pm
+++ b/lib/PublicInbox/NetReader.pm
@@ -319,14 +319,6 @@ sub cfg_intvl ($$$) {
}
}
-sub cfg_bool ($$$) {
- my ($cfg, $key, $url) = @_;
- my $orig = $cfg->urlmatch($key, $url) // return;
- my $bool = $cfg->git_bool($orig);
- warn "W: $key=$orig for $url is not boolean\n" unless defined($bool);
- $bool;
-}
-
# flesh out common IMAP-specific data structures
sub imap_common_init ($;$) {
my ($self, $lei) = @_;
@@ -344,8 +336,8 @@ sub imap_common_init ($;$) {
# knobs directly for Mail::IMAPClient->new
for my $k (qw(Starttls Debug Compress)) {
- my $bool = cfg_bool($cfg, "imap.$k", $$uri) // next;
- $mic_common->{$sec}->{$k} = $bool;
+ my $v = $cfg->urlmatch('--bool', "imap.$k", $$uri);
+ $mic_common->{$sec}->{$k} = $v if defined $v;
}
my $to = cfg_intvl($cfg, 'imap.timeout', $$uri);
$mic_common->{$sec}->{Timeout} = $to if $to;
@@ -398,7 +390,7 @@ sub nntp_common_init ($;$) {
my $args = $nn_common->{$sec} //= {};
# Debug and Timeout are passed to Net::NNTP->new
- my $v = cfg_bool($cfg, 'nntp.Debug', $$uri);
+ my $v = $cfg->urlmatch(qw(--bool nntp.Debug), $$uri);
$args->{Debug} = $v if defined $v;
my $to = cfg_intvl($cfg, 'nntp.Timeout', $$uri);
$args->{Timeout} = $to if $to;
@@ -407,8 +399,8 @@ sub nntp_common_init ($;$) {
# Net::NNTP post-connect commands
for my $k (qw(starttls compress)) {
- $v = cfg_bool($cfg, "nntp.$k", $$uri) // next;
- $self->{cfg_opt}->{$sec}->{$k} = $v;
+ $v = $cfg->urlmatch('--bool', "nntp.$k", $$uri);
+ $self->{cfg_opt}->{$sec}->{$k} = $v if defined $v;
}
# -watch internal option
diff --git a/t/imapd-tls.t b/t/imapd-tls.t
index 44ab350c..673a9436 100644
--- a/t/imapd-tls.t
+++ b/t/imapd-tls.t
@@ -158,8 +158,10 @@ for my $args (
test_lei(sub {
lei_ok qw(ls-mail-source), "imap://$starttls_addr",
\'STARTTLS not used by default';
- ok(!lei(qw(ls-mail-source -c imap.starttls=true),
+ ok(!lei(qw(ls-mail-source -c imap.starttls),
"imap://$starttls_addr"), 'STARTTLS verify fails');
+ unlike $lei_err, qr!W: imap\.starttls= .*? is not boolean!i,
+ 'no non-boolean warning';
});
SKIP: {
diff --git a/t/nntpd-tls.t b/t/nntpd-tls.t
index 2a76867a..095aef96 100644
--- a/t/nntpd-tls.t
+++ b/t/nntpd-tls.t
@@ -149,10 +149,12 @@ for my $args (
test_lei(sub {
lei_ok qw(ls-mail-source), "nntp://$starttls_addr",
\'STARTTLS not used by default';
- ok(!lei(qw(ls-mail-source -c nntp.starttls=true),
+ ok(!lei(qw(ls-mail-source -c nntp.starttls),
"nntp://$starttls_addr"), 'STARTTLS verify fails');
like $lei_err, qr/STARTTLS requested/,
'STARTTLS noted in stderr';
+ unlike $lei_err, qr!W: nntp\.starttls= .*? is not boolean!i,
+ 'no non-boolean warning';
});
SKIP: {
next prev parent reply other threads:[~2023-10-03 6:43 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-03 6:43 [PATCH 0/8] IMAP/NNTP client improvements Eric Wong
2023-10-03 6:43 ` [PATCH 1/8] net_reader: bail out on NNTP SOCKS connection failure Eric Wong
2023-10-03 6:43 ` [PATCH 2/8] net_reader: avoid IO::Socket::SSL 2.079..2.081 warning Eric Wong
2023-10-03 6:43 ` Eric Wong [this message]
2023-10-03 6:43 ` [PATCH 4/8] net_reader: support imap.sslVerify + nntp.sslVerify Eric Wong
2023-10-03 6:43 ` [PATCH 5/8] lei: workers exit after they tell lei-daemon Eric Wong
2023-10-03 6:43 ` [PATCH 6/8] net_reader: process title reflects NNTP article Eric Wong
2023-10-03 6:43 ` [PATCH 7/8] xt/lei-onion-convert: test TLS + SOCKS Eric Wong
2023-10-03 6:43 ` [PATCH 8/8] net_reader: note glob support in .onion hint Eric Wong
2023-10-03 7:11 ` "SSL" in option names is weird in 2023 Eric Wong
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
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231003064352.2902298-4-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).