CodeOwnerApprovalCheck: Skip the file path when looking up OWNERS files

When checking code owner approvals we iterate over all files that are
touched in the change and lookup the OWNERS files that are relevant for
them. For each file we start at the file path and then iterate up the
parent folders to look for OWNERS files. E.g. for file
"/foo/bar/baz.md" we check the following OWNERS files:
1. /foo/bar/baz.md/OWNERS
2. /foo/bar/OWNERS
3. /foo/OWNERS
4. /OWNERS

If we know that the given path is a file path, as in
CodeOwnerApprovalCheck, we can skip the first lookup as we know that
this OWNERS file will never exist.

The lower layers (CodeOwnerConfigHierarchy) accept arbitrary paths (file
paths and folder paths). Hence they must continue to check for the
"<path>/OWNERS" file.

Skipping this lookup in CodeOwnersApprovalCheck may look like an
optimization that is not worth doing, but we saw such lookups of
non-existing OWNERS files take up to 10ms, which sums up if you have
changes that touch 1000s of files.

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I9be58eb55183ef9177ae0c12b85691b5a26a7abd
2 files changed
tree: 433046fdd122646a67a6a3ea23d9a7b5589b2d62
  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.