CodeOwnerApprovalCheck: Allow to use diff cache to get changed files

To know if a change has sufficient code owner approvals to be
submittable or to compute the code owner file statuses we must know
which files were touched in a change. Since the PatchListCache was known
to be slow and having issues, the code-owners plugin implemented its own
changed file computation.

The disadvantages of this computation are:

- it is redone on each access (no caching)

- rename detection is switched off (as it is too expensive to be done on
  each access)

By now a new diff cache has been implemented and we want to make use of
it.

Using the new diff cache will enable the rename detection. This allows
us to report a single code owner status for renamed files now. This is
important because it means that the number of returned code owner
statuses will now match the number of changed files that are shown on
the change screen, and also the order will be consistent (that was not
the case when renamend files were reported as 2 code owner statuses, one
status for the old path and one status for the new path). In a follow-up
change we can make use of this and limit the number of returned code
owner statuses for large changes. For large changes the change screen
only shows the first 200 files. In this case it is sufficient to return
only the first 200 code owner statuses so that the files that are shown
on the change screen are covered.

Unfortunately we cannot use the new diff cache to get changed files in
all places yet:

- If changed files are computed to know which OWNERS files need to be
  validated it may be that the commit that should be validated was newly
  created and hence is only available from a specific RevWalk instance.
  Passing in this RevWalk instance into the diff cache is not possible
  and using another RevWalk instance would not find the commit and fail
  with MissingObjectException. The same problem applies with the old
  diff cache.

- The diff cache doesn't support getting changed files for initial
  commits (commits without parent commits).

Latency-wise it should be fine using the diff cache (with rename
detection being enabled) since the results are cached and any time a
change screen is viewed the cache is already being accessed.

Since the new diff cache still has a few issues, by default it is not
used yet, but there is an experiment flag that allows us to enable using
it. This way we can also safely roll this out when the new diff cache is
ready to be used.

Change-Id: Ifab1139e3e691523a5b0365eb271fdc7089b4c30
Signed-off-by: Edwin Kempin <ekempin@google.com>
12 files changed
tree: 82d0e020b4d0795b6b0d9d937f4a23edcefb8351
  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.