unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: Kyle Meyer <kyle@kyleam.com>
Cc: meta@public-inbox.org
Subject: Re: [PATCH 4/5] lei ls-mail-sync: fix handling of non-wildcard filters
Date: Tue, 4 May 2021 05:14:19 +0000	[thread overview]
Message-ID: <YJDYKxtVjWdRSW4q@dcvr> (raw)
In-Reply-To: <20210504044559.12941-5-kyle@kyleam.com>

Kyle Meyer <kyle@kyleam.com> wrote:
> If lei_ls_mail_sync() is given a filter without any wildcards and
> --globoff is unspecified, glob2re() will return undef, resulting in
> the final regular expression being undefined.  Add a fallback value.
> ---
> 
>   I'm not sure if this is the cleanest approach; repeating
>   qr/\Q$filter\E/ seems ugly.  I considered something closer to what
>   lei_ls_external() does, but decided against it because it leads to
>   --globoff with no filter showing no output, which I think is
>   surprising (even if passing --globoff with no filter doesn't make
>   any sense).

Thanks for bringing this up.

My code there was an insomnia-generated disaster :x
Mixing a ternary statement with a trailing "if" was just gross.

Below is a shorter, less-redundant rewrite based on your fix.

>   This probably deserves a test, but I'm out of time for tonight.  If
>   the change looks okay, I'm happy to look into adding a test
>   tomorrow.

Yes, but probably no rush.  I still need to get mail-sync
working... (sidetracked into working on "lei index" :x)

----------8<------------------------
Subject: [PATCH] lei ls-mail-sync: fix handling of non-wildcard filters

If lei_ls_mail_sync() is given a filter without any wildcards
and --globoff is unspecified, glob2re() will return undef,
resulting in the final regular expression being undefined.
Always use a fallback value when there's no RE.

Based-on-patch-by: Kyle Meyer <kyle@kyleam.com>
Link: https://public-inbox.org/meta/20210504044559.12941-5-kyle@kyleam.com/
---
 lib/PublicInbox/LeiLsMailSync.pm | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/lib/PublicInbox/LeiLsMailSync.pm b/lib/PublicInbox/LeiLsMailSync.pm
index 532ea9b5..505c0b3f 100644
--- a/lib/PublicInbox/LeiLsMailSync.pm
+++ b/lib/PublicInbox/LeiLsMailSync.pm
@@ -12,9 +12,8 @@ sub lei_ls_mail_sync {
 	my $sto = $lei->_lei_store or return;
 	my $lms = $sto->search->lms or return;
 	my $opt = $lei->{opt};
-	my $re;
-	$re = defined($filter) ? qr/\Q$filter\E/ : qr/./ if $opt->{globoff};
-	$re //= $lei->glob2re($filter // '*');
+	my $re = $opt->{globoff} ? undef : $lei->glob2re($filter // '*');
+	$re //= qr/\Q$filter\E/;
 	my @f = $lms->folders;
 	@f = $opt->{'invert-match'} ? grep(!/$re/, @f) : grep(/$re/, @f);
 	if ($opt->{'local'} && !$opt->{remote}) {

  reply	other threads:[~2021-05-04  5:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-04  4:45 [PATCH 0/5] Minor ls-mail-sync fixes Kyle Meyer
2021-05-04  4:45 ` [PATCH 1/5] lei ls-mail-sync: update reference to ls-sync Kyle Meyer
2021-05-04  4:45 ` [PATCH 2/5] lei ls-mail-sync: drop repeated -z/0 option Kyle Meyer
2021-05-04  4:45 ` [PATCH 3/5] lei ls-mail-sync: accept a filter Kyle Meyer
2021-05-04  4:45 ` [PATCH 4/5] lei ls-mail-sync: fix handling of non-wildcard filters Kyle Meyer
2021-05-04  5:14   ` Eric Wong [this message]
2021-05-04  4:45 ` [PATCH 5/5] lei: add help output for --invert match Kyle Meyer

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=YJDYKxtVjWdRSW4q@dcvr \
    --to=e@80x24.org \
    --cc=kyle@kyleam.com \
    --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).