Skip to contentSkip to conversation

get_maintainer.pl: Teach brace expansion

PATCH Superseded Anthony PERARD 2 participants 3 messages Jun 22, 2016 – Jun 24, 2016 GET_MAINTAINER script

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 get_maintainer.pl: Teach brace expansion

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 '(|)'.

---
 scripts/get_maintainer.pl | 11 +++++++++++
 1 file changed, 11 insertions(+)
scripts/get_maintainer.pl +11 -0
index 9fda278..40c6d03 100755
@@ -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");
Signature · 7 lines
Anthony PERARD


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#1 lore raw
Quoted 10 lines · Anthony PERARD

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

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#2 lore raw
Quoted 8 lines · George Dunlap
Quoted 6 lines · Anthony PERARD

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.

Quoted 8 lines
Quoted 4 lines

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.

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel