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
4 files changed
tree: 32b7249c04fd4ea402764a0d13a3ce653d946573
  1. java/
  2. javatests/
  3. proto/
  4. resources/
  5. test/
  6. ui/
  7. .eslintrc.json
  8. .gitignore
  9. .gitreview
  10. bower.json
  11. BUILD
  12. LICENSE
  13. package-lock.json
  14. package.json
  15. README.md
README.md

Gerrit Code Review code-owners plugin

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