From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 5A3DD1F47A for ; Fri, 17 Mar 2023 20:31:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1679085098; bh=6ASZlXxva8tiBs7wXA+jKfFfaGAE9gKW8evxQ37pJiQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=NY6/frc++0/zX/2bairuLvmZQg9CdH4Aui+n+LjRS05QYUJjQl85VRh7lX7xs12Gb V39Jo+ffBkxhnBe3VzztskKqGzedTqpo5hwuPaqVkdLLx6XxfdJFWXH1SqRjVzs5md /HYg2HWJxkBHcDqtmXXwq+EIzJ/flLMepvxPO2mo= From: Eric Wong 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 Message-Id: <20230317203137.1373098-3-e@80x24.org> In-Reply-To: <20230317203137.1373098-1-e@80x24.org> References: <20230317203137.1373098-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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();