unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/2] config: glob2re supports `**' to match multiple path components
Date: Fri, 17 Mar 2023 20:31:37 +0000	[thread overview]
Message-ID: <20230317203137.1373098-3-e@80x24.org> (raw)
In-Reply-To: <20230317203137.1373098-1-e@80x24.org>

This should match behavior documented in gitglossary(7)
---
 lib/PublicInbox/Config.pm | 3 ++-
 t/config.t                | 5 +++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index 34abcea3..4065b256 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -580,6 +580,7 @@ sub squote_maybe ($) {
 }
 
 my %re_map = ( '*' => '[^/]*?', '?' => '[^/]',
+		'/**' => '/.*', '**/' => '.*/', '/**/' => '/.*?',
 		'[' => '[', ']' => ']', ',' => ',' );
 
 sub glob2re ($) {
@@ -593,7 +594,7 @@ sub glob2re ($) {
 	if ($re =~ s!\A([a-z0-9\+]+://\[[a-f0-9\:]+\](?::[0-9]+)?/)!!i) {
 		$schema_host_port = quotemeta $1; # "http://[::1]:1234"
 	}
-	my $changes = ($re =~ s!(.)!
+	my $changes = ($re =~ s!(/\*\*/|\A\*\*/|/\*\*\z|.)!
 		$re_map{$p eq '\\' ? '' : do {
 			if ($1 eq '[') { ++$in_bracket }
 			elsif ($1 eq ']') { --$in_bracket }
diff --git a/t/config.t b/t/config.t
index d67931da..80f214cd 100644
--- a/t/config.t
+++ b/t/config.t
@@ -274,5 +274,10 @@ is_deeply($glob2re->('*.[ch]'), '[^/]*?\\.[ch]', 'suffix glob');
 is_deeply($glob2re->('{[a-z],9,}'), '([a-z]|9|)' , 'brace with range');
 is_deeply($glob2re->('\\{a,b\\}'), undef, 'escaped brace');
 is_deeply($glob2re->('\\\\{a,b}'), '\\\\\\\\(a|b)', 'fake escape brace');
+is_deeply($glob2re->('**/foo'), '.*/foo', 'double asterisk start');
+is_deeply($glob2re->('foo/**'), 'foo/.*', 'double asterisk end');
+my $re = $glob2re->('a/**/b');
+is_deeply($re, 'a/.*?b', 'double asterisk middle');
+like($_, qr!$re!, "a/**/b matches $_") for ('a/b', 'a/c/b', 'a/c/a/b');
 
 done_testing();

      parent reply	other threads:[~2023-03-17 20:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-17 20:31 [PATCH 0/2] globbing updates Eric Wong
2023-03-17 20:31 ` [PATCH 1/2] treewide: move glob2re to PublicInbox::Config Eric Wong
2023-03-17 20:31 ` Eric Wong [this message]

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=20230317203137.1373098-3-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).