about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-03-17 20:31:37 +0000
committerEric Wong <e@80x24.org>2023-03-18 04:17:47 +0000
commit14454a6be768159c611e4fb892bf08b1efcd6b89 (patch)
tree354933bd8ba233191e5b617689d522efed2aa856
parentbc6ef574030069c5b438e33fb06cd2680bc86d68 (diff)
downloadpublic-inbox-14454a6be768159c611e4fb892bf08b1efcd6b89.tar.gz
This should match behavior documented in gitglossary(7)
-rw-r--r--lib/PublicInbox/Config.pm3
-rw-r--r--t/config.t5
2 files changed, 7 insertions, 1 deletions
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();