diff mbox

get_maintainer.pl: Teach brace expansion

Message ID 20160622172815.6699-1-anthony.perard@citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Anthony PERARD June 22, 2016, 5:28 p.m. UTC
This only implement a simpler non-nested brace expansion.

This will convert brace expansion style use in MAINTAINER into a regex
that get_maintainer.pl can use to match a path again a maintainer
section.

It is done by using two different regex, the first one will take care of
converting ',' inside '{}' to a '|', one by one, as long as there is at
least two commas. The second regex will do the final convertion of '{,}'
to '(|)'.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
 scripts/get_maintainer.pl | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

George Dunlap June 24, 2016, 11:09 a.m. UTC | #1
On Wed, Jun 22, 2016 at 6:28 PM, Anthony PERARD
<anthony.perard@citrix.com> wrote:
> This only implement a simpler non-nested brace expansion.
>
> This will convert brace expansion style use in MAINTAINER into a regex
> that get_maintainer.pl can use to match a path again a maintainer
> section.
>
> It is done by using two different regex, the first one will take care of
> converting ',' inside '{}' to a '|', one by one, as long as there is at
> least two commas. The second regex will do the final convertion of '{,}'
> to '(|)'.

Can you give some examples of the sorts of MAINTAINER entries this
would allow (and maybe one that you intend to implement once this is
accepted)?

Thanks,
 -George
Anthony PERARD June 24, 2016, 11:33 a.m. UTC | #2
On Fri, Jun 24, 2016 at 12:09:53PM +0100, George Dunlap wrote:
> On Wed, Jun 22, 2016 at 6:28 PM, Anthony PERARD
> <anthony.perard@citrix.com> wrote:
> > This only implement a simpler non-nested brace expansion.
> >
> > This will convert brace expansion style use in MAINTAINER into a regex
> > that get_maintainer.pl can use to match a path again a maintainer
> > section.
> >
> > It is done by using two different regex, the first one will take care of
> > converting ',' inside '{}' to a '|', one by one, as long as there is at
> > least two commas. The second regex will do the final convertion of '{,}'
> > to '(|)'.
> 
> Can you give some examples of the sorts of MAINTAINER entries this
> would allow (and maybe one that you intend to implement once this is
> accepted)?

With this patch, every entry of the current MAINTAINER file would work!
The one below for example would return the right sections/maintainers.
$ ./scripts/get_maintainer.pl --sections -f xen/common/kexec.c

Also, for every invocation of the script, I've got this message (x3)
(without the patch):
Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/^xen/common/{ <-- HERE kexec,kimage}\.c/ at ./scripts/get_maintainer.pl line 731.

One example I've tried the patch with, by adding a bogus entry:
  xen/common/{kexec,kimage,extra,patterns}.{c,h,S}

By the way, --sections does not print the original pattern, but it print
the pattern converted by to globing from the regex.
diff mbox

Patch

diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl
index 9fda278..40c6d03 100755
--- a/scripts/get_maintainer.pl
+++ b/scripts/get_maintainer.pl
@@ -283,6 +283,12 @@  while (<$maint>) {
 
 	##Filename pattern matching
 	if ($type eq "F" || $type eq "X") {
+	    # Bash brace expansion, not nested
+	    # match {,*,*} and transform ',' to '|' one by one.
+	    while ($value =~ s/([^\\])\{(|[^},]*[^,\\]),((|[^},]*[^,\\]),(|[^}]*[^\\]))\}/$1\{$2|$3\}/g) {}
+	    # Finish convertion by transforming '{,}' to '(|)'
+	    $value =~ s/([^\\])\{(|[^},]*[^,\\]),(|[^}]*[^\\])\}/$1($2|$3)/g;
+
 	    $value =~ s@\.@\\\.@g;       ##Convert . to \.
 	    $value =~ s/\*/\.\*/g;       ##Convert * to .*
 	    $value =~ s/\?/\./g;         ##Convert ? to .
@@ -637,6 +643,11 @@  sub get_maintainers {
 			$line =~ s/([^\\])\.$/$1\?/g;	##Convert . back to ?
 			$line =~ s/\\\./\./g;       	##Convert \. to .
 			$line =~ s/\.\*/\*/g;       	##Convert .* to *
+			## Convert (|) back to {,}
+			# match (|*|*) and transform '|' to ',' one by one
+			while ($line =~ s/([^\\])\((|[^)|]*[^|\\])\|((|[^)|]*[^|\\])\|(|[^)]*[^\\]))\)/$1($2,$3)/g) {}
+                        # Finish convertion by transforming '(|)' to '{,}'
+			$line =~ s/([^\\])\((|[^)|]*[^|\\])\|(|[^)]*[^\\])\)/$1\{$2,$3\}/g;
 		    }
 		    $line =~ s/^([A-Z]):/$1:\t/g;
 		    print("$line\n");