| commit | 91bba01d7ad01b83133b29324e131389deb7a80a | [log] [tgz] |
|---|---|---|
| author | Edwin Kempin <ekempin@google.com> | Fri Jan 29 11:13:33 2021 +0100 |
| committer | Edwin Kempin <ekempin@google.com> | Fri Jan 29 14:37:16 2021 +0100 |
| tree | 32b7249c04fd4ea402764a0d13a3ce653d946573 | |
| parent | e8bedb10e9357f7e4607e7685eda6fc7a206d6f1 [diff] |
FindOwnersBackend: Fix incompatibility of handling globs
The find-owners backend promises to be compatible with the syntax of the
find-owners plugin, but currently the handling of globs differs.
The find-owners plugin ignores subdirectories when checking if a glob
matches a file.
Examples:
1. the glob "*.md" in "/" matches "foo.md", "bar/foo.md" and
"baz/bar/foo.md"
2. the glob "BUILD" in "/" matches "BUILD", "bar/BUILD" and
"baz/bar/BUILD"
3. the glob "foo-[1-4].txt" in "/" matches "foo-1.txt", "bar/foo-1.txt"
and "baz/bar/foo-1.txt"
This is because the find-owners plugin iterates over all parent
directories [1,2] to see if there is a glob that matches the
filename [3]. E.g. if the glob "*.md" is defined at '/' and the file
path is "baz/bar/foo.md" then it does the following checks:
a. Is there a glob at "./baz/bar" that matches file "./baz/bar/foo.md" (no)
b. Is there a glob at "./baz" that matches file "./baz/foo.md" (no)
c. Is there a glob at "./" that matches file "./foo.md" (yes)
Effectively this means that subdirectories are ignored (although the
actual file is "./baz/bar/foo.md" the find-owners plugin checks the glob
against "./foo.md").
To be compatible with this behaviour the code-owners plugin needs to
ignore subdirectories too when checking if a file matches a glob.
Instead of iterating over the parent directories for each file as it's
done in the find-owners plugin, we simply prefix all globs with "{**/,}"
("{**/,}" matches "**/" or "", which matches any subdirectory and no
subdirectory).
Change I1ddc8bf32 was a first attempt to fix this by replacing "*" with
"**" in globs, but this only fixed case 1 (and not the cases 2 and 3).
[1] https://gerrit.googlesource.com/plugins/find-owners/+/refs/heads/master/src/main/java/com/googlesource/gerrit/plugins/findowners/OwnersDb.java#367
[2] https://gerrit.googlesource.com/plugins/find-owners/+/refs/heads/master/src/main/java/com/googlesource/gerrit/plugins/findowners/OwnersDb.java#396
[3] https://gerrit.googlesource.com/plugins/find-owners/+/refs/heads/master/src/main/java/com/googlesource/gerrit/plugins/findowners/OwnersDb.java#375
Bug: Issue 14008
Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I04931606858511fb1c36c449a4ce3f2300eabecf
This plugin provides support for defining code owners for files in a repository.
If the code-owners plugin is enabled, changes can only be submitted if all touched files are covered by approvals from code owners.
Also see resources/Documentation/about.md
IMPORTANT: Before installing/enabling the plugin follow the instructions from the setup guide, see resources/Documentation/setup-guide.md