CheckCodeOwnerConfigFilesInRevision: Get changed files without rename detection CheckCodeOwnerConfigFilesInRevision checks OWNERS files in a revision. For this we do not care about renames and deletions, hence rename detection is not needed here. Change-Id: Iedb2f65698eaae073a61b0e926c5d188af31e45b Signed-off-by: Edwin Kempin <ekempin@google.com>
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/ChangedFiles.java b/java/com/google/gerrit/plugins/codeowners/backend/ChangedFiles.java index ccbb5ba..6c77dd0 100644 --- a/java/com/google/gerrit/plugins/codeowners/backend/ChangedFiles.java +++ b/java/com/google/gerrit/plugins/codeowners/backend/ChangedFiles.java
@@ -75,18 +75,23 @@ /** * Gets the changed files. * - * <p>Rename detection is enabled. + * <p>Rename detection is disabled. + * + * <p>Uses the configured merge commit strategy. * * @param project the project * @param revision the revision for which the changed files should be retrieved - * @param mergeCommitStrategy the merge commit strategy that should be used to compute the changed - * files for merge commits * @return the files that have been changed in the given revision, sorted alphabetically by path + * @throws IOException thrown if the computation fails due to an I/O error */ - public ImmutableList<ChangedFile> get( - Project.NameKey project, ObjectId revision, MergeCommitStrategy mergeCommitStrategy) - throws IOException, DiffNotAvailableException { - return get(project, revision, mergeCommitStrategy, /* enableRenameDetection= */ true); + public ImmutableList<ChangedFile> getWithoutRenameDetection( + Project.NameKey project, ObjectId revision) throws IOException, DiffNotAvailableException { + requireNonNull(project, "project"); + requireNonNull(revision, "revision"); + return getWithoutRenameDetection( + project, + revision, + codeOwnersPluginConfiguration.getProjectConfig(project).getMergeCommitStrategy()); } /** @@ -106,6 +111,63 @@ return get(project, revision, mergeCommitStrategy, /* enableRenameDetection= */ false); } + /** + * Gets the changed files. + * + * <p>Rename detection is enabled. + * + * <p>Uses the configured merge commit strategy. + * + * @param revisionResource the revision resource for which the changed files should be retrieved + * @return the files that have been changed in the given revision, sorted alphabetically by path + * @throws IOException thrown if the computation fails due to an I/O error + * @see #get(Project.NameKey, ObjectId, MergeCommitStrategy) + */ + public ImmutableList<ChangedFile> get(RevisionResource revisionResource) + throws IOException, DiffNotAvailableException { + requireNonNull(revisionResource, "revisionResource"); + return get(revisionResource.getProject(), revisionResource.getPatchSet().commitId()); + } + + /** + * Gets the changed files. + * + * <p>Rename detection is enabled. + * + * <p>Uses the configured merge commit strategy. + * + * @param project the project + * @param revision the revision for which the changed files should be retrieved + * @return the files that have been changed in the given revision, sorted alphabetically by path + * @throws IOException thrown if the computation fails due to an I/O error + */ + public ImmutableList<ChangedFile> get(Project.NameKey project, ObjectId revision) + throws IOException, DiffNotAvailableException { + requireNonNull(project, "project"); + requireNonNull(revision, "revision"); + return get( + project, + revision, + codeOwnersPluginConfiguration.getProjectConfig(project).getMergeCommitStrategy()); + } + + /** + * Gets the changed files. + * + * <p>Rename detection is enabled. + * + * @param project the project + * @param revision the revision for which the changed files should be retrieved + * @param mergeCommitStrategy the merge commit strategy that should be used to compute the changed + * files for merge commits + * @return the files that have been changed in the given revision, sorted alphabetically by path + */ + public ImmutableList<ChangedFile> get( + Project.NameKey project, ObjectId revision, MergeCommitStrategy mergeCommitStrategy) + throws IOException, DiffNotAvailableException { + return get(project, revision, mergeCommitStrategy, /* enableRenameDetection= */ true); + } + private ImmutableList<ChangedFile> get( Project.NameKey project, ObjectId revision, @@ -146,46 +208,6 @@ } /** - * Gets the changed files. - * - * <p>Rename detection is enabled. - * - * <p>Uses the configured merge commit strategy. - * - * @param project the project - * @param revision the revision for which the changed files should be retrieved - * @return the files that have been changed in the given revision, sorted alphabetically by path - * @throws IOException thrown if the computation fails due to an I/O error - */ - public ImmutableList<ChangedFile> get(Project.NameKey project, ObjectId revision) - throws IOException, DiffNotAvailableException { - requireNonNull(project, "project"); - requireNonNull(revision, "revision"); - return get( - project, - revision, - codeOwnersPluginConfiguration.getProjectConfig(project).getMergeCommitStrategy()); - } - - /** - * Gets the changed files. - * - * <p>Rename detection is enabled. - * - * <p>Uses the configured merge commit strategy. - * - * @param revisionResource the revision resource for which the changed files should be retrieved - * @return the files that have been changed in the given revision, sorted alphabetically by path - * @throws IOException thrown if the computation fails due to an I/O error - * @see #get(Project.NameKey, ObjectId, MergeCommitStrategy) - */ - public ImmutableList<ChangedFile> get(RevisionResource revisionResource) - throws IOException, DiffNotAvailableException { - requireNonNull(revisionResource, "revisionResource"); - return get(revisionResource.getProject(), revisionResource.getPatchSet().commitId()); - } - - /** * Gets the changed files from {@link DiffOperationsForCommitValidation} which needs to be used to * retrieve modified files during commit validation. *
diff --git a/java/com/google/gerrit/plugins/codeowners/restapi/CheckCodeOwnerConfigFilesInRevision.java b/java/com/google/gerrit/plugins/codeowners/restapi/CheckCodeOwnerConfigFilesInRevision.java index 930ab0f..70a425a 100644 --- a/java/com/google/gerrit/plugins/codeowners/restapi/CheckCodeOwnerConfigFilesInRevision.java +++ b/java/com/google/gerrit/plugins/codeowners/restapi/CheckCodeOwnerConfigFilesInRevision.java
@@ -95,7 +95,8 @@ RevWalk rw = new RevWalk(repository)) { RevCommit commit = rw.parseCommit(revisionResource.getPatchSet().commitId()); return Response.ok( - changedFiles.get(revisionResource.getProject(), commit).stream() + // We are only interested in the new paths, hence rename detection is not needed. + changedFiles.getWithoutRenameDetection(revisionResource.getProject(), commit).stream() // filter out deletions (files without new path) .filter(changedFile -> changedFile.newPath().isPresent()) // filter out non code owner config files