summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niewöhner <foss@mniewoehner.de>2021-04-13 00:17:39 +0200
committerPatrick Georgi <pgeorgi@google.com>2021-04-14 10:50:18 +0000
commit158fed9ee72ff09b5f8237c42910b406727caa9c (patch)
tree315a7b2b29e3d037851d4494431630f1a85c0248
parent20e04efc3316a02deac325598a02696af01b440d (diff)
downloadcoreboot-158fed9ee72ff09b5f8237c42910b406727caa9c.tar.gz
coreboot-158fed9ee72ff09b5f8237c42910b406727caa9c.tar.bz2
coreboot-158fed9ee72ff09b5f8237c42910b406727caa9c.zip
maintainers.go: correct handling of globs
maintainers.go does not handle globs as described in MAINTAINERS. Instead of only matching the files inside a directory, it also matches everything below. Also, a glob used in between (`e.g. path/to/*/dir`) could lead to matching many more paths unexpectedly. This is caused by the way paths using globs are converted to regegular expressions for use with gerrit: 1. The script converts all paths with trailing slash to a path with trailing glob. That means, a recursive match on a directory gets converted to match only the files in the directory (at least according to the documentation - if there wasn't 2). Example: `path/to/dir/` becomes `path/to/dir/*` 2. When converting the path to a regex, all globs get converted to prefix matching by replacing the glob by `.*`. Instead of only matching the files in the directory, everything below matches, which is a) not what the documentation states and b) the opposite of what 1. did first. Example: `path/to/dir/*` becomes `^path/to/dir/.*$` In sum, this leads to all sorts of issues. Examples: - `path/*/dir` becomes `^path/.*/dir$` - `path/to/dir/*` becomes `^path/to/dir/.*$` - `path/to/*.c` becomes `^path/to/.*\.c$` This change fixes that behaviour by: - dropping the wrong conversion from 1. above. - fixing glob matching by replacing `*` by `[^/]`. - handling paths with trailing `/` as prefix, as documented. The change was not split because these changes depend on each other and splitting would break recursive matching between the commits. Tests: 1. diffed output before and after is equal (!= the same) 2. manual testing of glob matching Change-Id: I4347a60874e4f07e41bdee43cc312547bea99008 Signed-off-by: Michael Niewöhner <foss@mniewoehner.de> Reviewed-on: https://review.coreboot.org/c/coreboot/+/52275 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Patrick Georgi <pgeorgi@google.com> Reviewed-by: Nico Huber <nico.h@gmx.de>
-rw-r--r--util/scripts/maintainers.go13
1 files changed, 8 insertions, 5 deletions
diff --git a/util/scripts/maintainers.go b/util/scripts/maintainers.go
index 459c030d1360..c68ea058f01d 100644
--- a/util/scripts/maintainers.go
+++ b/util/scripts/maintainers.go
@@ -77,11 +77,14 @@ func get_maintainers() ([]string, error) {
}
func path_to_regexstr(path string) string {
- // if prefix, allow all subdirectories
- if path[len(path)-1] == '/' {
- path += "*"
+ regexstr := glob_to_regex(path)
+
+ /* Handle path with trailing '/' as prefix */
+ if regexstr[len(regexstr)-2:] == "/$" {
+ regexstr = regexstr[:len(regexstr)-1] + ".*$"
}
- return glob_to_regex(path)
+
+ return regexstr;
}
func path_to_regex(path string) *regexp.Regexp {
@@ -200,7 +203,7 @@ func glob_to_regex(glob string) string {
}
case '*':
if inClass == 0 {
- regex += ".*"
+ regex += "[^/]*"
} else {
regex += "*"
}