From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 176F41F933 for ; Sat, 27 Jun 2020 10:04:05 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 26/34] watch: just use ->urlmatch Date: Sat, 27 Jun 2020 10:03:52 +0000 Message-Id: <20200627100400.9871-27-e@yhbt.net> In-Reply-To: <20200627100400.9871-1-e@yhbt.net> References: <20200627100400.9871-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We may just modify PublicInbox::Config->urlmatch in the future to support git <1.8.5, but I wonder if there's enough users on git <1.8.5 to justify it. --- lib/PublicInbox/WatchMaildir.pm | 32 ++++++++++++++------------------ t/imapd.t | 4 +++- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm index 8d2dc432684..535dadd539c 100644 --- a/lib/PublicInbox/WatchMaildir.pm +++ b/lib/PublicInbox/WatchMaildir.pm @@ -235,11 +235,9 @@ sub imap_section ($) { $uri->scheme . '://' . $uri->authority; } -sub cfg_intvl ($$$$$) { - my ($cfg, $cfg_section, $cfg_key, $imap_section, $url) = @_; - my $key = "$cfg_section.$imap_section.$cfg_key"; - my $v = $cfg->{lc($key)} // - $cfg->urlmatch("$cfg_section.$cfg_key", $url) // return; +sub cfg_intvl ($$$) { + my ($cfg, $key, $url) = @_; + my $v = $cfg->urlmatch($key, $url) // return; $v =~ /\A[0-9]+(?:\.[0-9]+)?\z/s and return $v + 0; if (ref($v) eq 'ARRAY') { $v = join(', ', @$v); @@ -257,31 +255,29 @@ sub imap_common_init ($) { for my $url (sort keys %{$self->{imap}}) { my $uri = PublicInbox::URIimap->new($url); my $sec = imap_section($uri); - for my $k (qw(Starttls Debug Compress)) { - my $key = lc("imap.$sec.$k"); - my $orig = $cfg->{$key} // - $cfg->urlmatch("imap.$k", $url) // next; + for my $f (qw(Starttls Debug Compress)) { + my $k = "imap.$f"; + my $orig = $cfg->urlmatch($k, $url) // next; my $v = PublicInbox::Config::_git_config_bool($orig); if (defined($v)) { - $mic_args->{$sec}->{$k} = $v; + $mic_args->{$sec}->{$f} = $v; } else { - warn "W: $key=$orig is not boolean\n"; + warn "W: $k=$orig for $url is not boolean\n"; } } - my $to = cfg_intvl($cfg, 'imap', 'Timeout', $sec, $url); + my $to = cfg_intvl($cfg, 'imap.timeout', $url); $mic_args->{$sec}->{Timeout} = $to if $to; - $to = cfg_intvl($cfg, 'imap', 'PollInterval', $sec, $url); + $to = cfg_intvl($cfg, 'imap.pollInterval', $url); $self->{imap_opt}->{$sec}->{poll_intvl} = $to if $to; - $to = cfg_intvl($cfg, 'imap', 'IdleInterval', $sec, $url); + $to = cfg_intvl($cfg, 'imap.IdleInterval', $url); $self->{imap_opt}->{$sec}->{idle_intvl} = $to if $to; - my $key = lc("imap.$sec.fetchBatchSize"); - my $bs = $cfg->{lc($key)} // - $cfg->urlmatch('imap.fetchBatchSize', $url) // next; + my $k = 'imap.fetchBatchSize'; + my $bs = $cfg->urlmatch($k, $url) // next; if ($bs =~ /\A([0-9]+)\z/) { $self->{imap_opt}->{$sec}->{batch_size} = $bs; } else { - warn "W: $key=$bs is not an integer\n"; + warn "$k=$bs is not an integer\n"; } } $mic_args; diff --git a/t/imapd.t b/t/imapd.t index 5626d24765f..cf327e9fbea 100644 --- a/t/imapd.t +++ b/t/imapd.t @@ -440,9 +440,11 @@ ok($mic->logout, 'logged out'); like(<$c>, qr/\Atagonly BAD Error in IMAP command/, 'tag-only line'); } -{ +SKIP: { use_ok 'PublicInbox::WatchMaildir'; use_ok 'PublicInbox::InboxIdle'; + require_git('1.8.5', 1) or + skip('git 1.8.5+ needed for --urlmatch', 4); my $old_env = { HOME => $ENV{HOME} }; my $home = "$tmpdir/watch_home"; mkdir $home or BAIL_OUT $!;