mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] get_maintainer: add ** globstar pattern support
@ 2026-03-02  2:53 Matteo Croce
  2026-03-02  3:45 ` Joe Perches
  2026-03-02  3:59 ` Joe Perches
  0 siblings, 2 replies; 3+ messages in thread
From: Matteo Croce @ 2026-03-02  2:53 UTC (permalink / raw)
  To: Joe Perches; +Cc: linux-kernel

Add support for the ** globstar operator in MAINTAINERS F: and X: patterns,
matching any number of path components (like Python's ** glob).

The existing * to .* conversion with slash-count check is preserved.
** is converted to (?:.*), a non-capturing group used as a marker to
bypass the slash-count check in file_match_pattern(), allowing the
pattern to cross directory boundaries.

Tested by running `scripts/get_maintainer.pl --self-test=patterns`
with the following line added to MAINTAINERS:

    F: **/*[_-]kunit*.c

Signed-off-by: Matteo Croce <teknoraver@meta.com>
---
 scripts/get_maintainer.pl | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl
index 4414194bedcf..f0ca0db6ddc2 100755
--- a/scripts/get_maintainer.pl
+++ b/scripts/get_maintainer.pl
@@ -375,8 +375,10 @@ sub read_maintainer_file {
 	    ##Filename pattern matching
 	    if ($type eq "F" || $type eq "X") {
 		$value =~ s@\.@\\\.@g;       ##Convert . to \.
+		$value =~ s/\*\*/\x00/g;     ##Convert ** to placeholder
 		$value =~ s/\*/\.\*/g;       ##Convert * to .*
 		$value =~ s/\?/\./g;         ##Convert ? to .
+		$value =~ s/\x00/(?:.*)/g;   ##Convert placeholder to (?:.*)
 		##if pattern is a directory and it lacks a trailing slash, add one
 		if ((-d $value)) {
 		    $value =~ s@([^/])$@$1/@;
@@ -746,8 +748,10 @@ sub self_test {
 	if (($type eq "F" || $type eq "X") &&
 	    ($self_test eq "" || $self_test =~ /\bpatterns\b/)) {
 	    $value =~ s@\.@\\\.@g;       ##Convert . to \.
+	    $value =~ s/\*\*/\x00/g;     ##Convert ** to placeholder
 	    $value =~ s/\*/\.\*/g;       ##Convert * to .*
 	    $value =~ s/\?/\./g;         ##Convert ? to .
+	    $value =~ s/\x00/(?:.*)/g;   ##Convert placeholder to (?:.*)
 	    ##if pattern is a directory and it lacks a trailing slash, add one
 	    if ((-d $value)) {
 		$value =~ s@([^/])$@$1/@;
@@ -921,7 +925,7 @@ sub get_maintainers {
 				my $value_pd = ($value =~ tr@/@@);
 				my $file_pd = ($file  =~ tr@/@@);
 				$value_pd++ if (substr($value,-1,1) ne "/");
-				$value_pd = -1 if ($value =~ /^\.\*/);
+				$value_pd = -1 if ($value =~ /^(\.\*|\(\?:\.\*\))/);
 				if ($value_pd >= $file_pd &&
 				    range_is_maintained($start, $end) &&
 				    range_has_maintainer($start, $end)) {
@@ -955,6 +959,7 @@ sub get_maintainers {
 			$line =~ s/([^\\])\.([^\*])/$1\?$2/g;
 			$line =~ s/([^\\])\.$/$1\?/g;	##Convert . back to ?
 			$line =~ s/\\\./\./g;       	##Convert \. to .
+			$line =~ s/\(\?:\.\*\)/\*\*/g;	##Convert (?:.*) to **
 			$line =~ s/\.\*/\*/g;       	##Convert .* to *
 		    }
 		    my $count = $line =~ s/^([A-Z]):/$1:\t/g;
@@ -1048,7 +1053,7 @@ sub file_match_pattern {
 	if ($file =~ m@^$pattern@) {
 	    my $s1 = ($file =~ tr@/@@);
 	    my $s2 = ($pattern =~ tr@/@@);
-	    if ($s1 == $s2) {
+	    if ($s1 == $s2 || $pattern =~ /\(\?:/) {
 		return 1;
 	    }
 	}
-- 
2.53.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] get_maintainer: add ** globstar pattern support
  2026-03-02  2:53 [PATCH] get_maintainer: add ** globstar pattern support Matteo Croce
@ 2026-03-02  3:45 ` Joe Perches
  2026-03-02  3:59 ` Joe Perches
  1 sibling, 0 replies; 3+ messages in thread
From: Joe Perches @ 2026-03-02  3:45 UTC (permalink / raw)
  To: Matteo Croce, Andrew Morton; +Cc: linux-kernel

On Mon, 2026-03-02 at 03:53 +0100, Matteo Croce wrote:
> Add support for the ** globstar operator in MAINTAINERS F: and X: patterns,
> matching any number of path components (like Python's ** glob).
> 
> The existing * to .* conversion with slash-count check is preserved.
> ** is converted to (?:.*), a non-capturing group used as a marker to
> bypass the slash-count check in file_match_pattern(), allowing the
> pattern to cross directory boundaries.
> 
> Tested by running `scripts/get_maintainer.pl --self-test=patterns`
> with the following line added to MAINTAINERS:
> 
>     F: **/*[_-]kunit*.c
> 
> Signed-off-by: Matteo Croce <[teknoraver@meta.com](mailto:teknoraver@meta.com)>

Simpler, thanks.

Acked-by: Joe Perches <joe@perches.com>

> ---
>  scripts/get_maintainer.pl | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl
> index 4414194bedcf..f0ca0db6ddc2 100755
> --- a/scripts/get_maintainer.pl
> +++ b/scripts/get_maintainer.pl
> @@ -375,8 +375,10 @@ sub read_maintainer_file {
>  	    ##Filename pattern matching
>  	    if ($type eq "F" || $type eq "X") {
>  		$value =~ s@\.@\\\.@g;       ##Convert . to \.
> +		$value =~ s/\*\*/\x00/g;     ##Convert ** to placeholder
>  		$value =~ s/\*/\.\*/g;       ##Convert * to .*
>  		$value =~ s/\?/\./g;         ##Convert ? to .
> +		$value =~ s/\x00/(?:.*)/g;   ##Convert placeholder to (?:.*)
>  		##if pattern is a directory and it lacks a trailing slash, add one
>  		if ((-d $value)) {
>  		    $value =~ s@([^/])$@$1/@;
> @@ -746,8 +748,10 @@ sub self_test {
>  	if (($type eq "F" || $type eq "X") &&
>  	    ($self_test eq "" || $self_test =~ /\bpatterns\b/)) {
>  	    $value =~ s@\.@\\\.@g;       ##Convert . to \.
> +	    $value =~ s/\*\*/\x00/g;     ##Convert ** to placeholder
>  	    $value =~ s/\*/\.\*/g;       ##Convert * to .*
>  	    $value =~ s/\?/\./g;         ##Convert ? to .
> +	    $value =~ s/\x00/(?:.*)/g;   ##Convert placeholder to (?:.*)
>  	    ##if pattern is a directory and it lacks a trailing slash, add one
>  	    if ((-d $value)) {
>  		$value =~ s@([^/])$@$1/@;
> @@ -921,7 +925,7 @@ sub get_maintainers {
>  				my $value_pd = ($value =~ tr@/@@);
>  				my $file_pd = ($file  =~ tr@/@@);
>  				$value_pd++ if (substr($value,-1,1) ne "/");
> -				$value_pd = -1 if ($value =~ /^\.\*/);
> +				$value_pd = -1 if ($value =~ /^(\.\*|\(\?:\.\*\))/);
>  				if ($value_pd >= $file_pd &&
>  				    range_is_maintained($start, $end) &&
>  				    range_has_maintainer($start, $end)) {
> @@ -955,6 +959,7 @@ sub get_maintainers {
>  			$line =~ s/([^\\])\.([^\*])/$1\?$2/g;
>  			$line =~ s/([^\\])\.$/$1\?/g;	##Convert . back to ?
>  			$line =~ s/\\\./\./g;       	##Convert \. to .
> +			$line =~ s/\(\?:\.\*\)/\*\*/g;	##Convert (?:.*) to **
>  			$line =~ s/\.\*/\*/g;       	##Convert .* to *
>  		    }
>  		    my $count = $line =~ s/^([A-Z]):/$1:\t/g;
> @@ -1048,7 +1053,7 @@ sub file_match_pattern {
>  	if ($file =~ m@^$pattern@) {
>  	    my $s1 = ($file =~ tr@/@@);
>  	    my $s2 = ($pattern =~ tr@/@@);
> -	    if ($s1 == $s2) {
> +	    if ($s1 == $s2 || $pattern =~ /\(\?:/) {
>  		return 1;
>  	    }
>  	}
> 
> ```

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] get_maintainer: add ** globstar pattern support
  2026-03-02  2:53 [PATCH] get_maintainer: add ** globstar pattern support Matteo Croce
  2026-03-02  3:45 ` Joe Perches
@ 2026-03-02  3:59 ` Joe Perches
  1 sibling, 0 replies; 3+ messages in thread
From: Joe Perches @ 2026-03-02  3:59 UTC (permalink / raw)
  To: Matteo Croce; +Cc: linux-kernel

On Mon, 2026-03-02 at 03:53 +0100, Matteo Croce wrote:
> Add support for the ** globstar operator in MAINTAINERS F: and X: patterns,
> matching any number of path components (like Python's ** glob).

Maybe when you add your ** entry to MAINTAINERS, update the
file pattern block description to include the new ** glob.

Maybe something like:
---
diff --git a/MAINTAINERS b/MAINTAINERS
index 14899f1de77ed..0e7059f9765cb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -35,6 +35,7 @@ Descriptions of section entries and preferred order
 	   F:   drivers/net/    all files in and below drivers/net
 	   F:   drivers/net/*   all files in drivers/net, but not below
 	   F:   */net/*         all files in "any top level directory"/net
+	   F:   fs/**/*foo*.c   all *foo*.c files in any subdirectory of fs
 	   One pattern per line.  Multiple F: lines acceptable.
 	X: *Excluded* files and directories that are NOT maintained, same
 	   rules as F:. Files exclusions are tested before file matches.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-03-02  3:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-02  2:53 [PATCH] get_maintainer: add ** globstar pattern support Matteo Croce
2026-03-02  3:45 ` Joe Perches
2026-03-02  3:59 ` Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®