Line data Source code
1 : // Copyright (C) 2021 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.change; 16 : 17 : import com.google.gerrit.common.Nullable; 18 : import com.google.gerrit.entities.Change; 19 : import com.google.gerrit.entities.PatchSet; 20 : import com.google.gerrit.entities.Project; 21 : import com.google.gerrit.extensions.common.FileInfo; 22 : import com.google.gerrit.extensions.restapi.ResourceConflictException; 23 : import com.google.gerrit.server.patch.PatchListNotAvailableException; 24 : import java.util.Map; 25 : import org.eclipse.jgit.lib.ObjectId; 26 : 27 : /** Compute and return the list of modified files between two commits. */ 28 : public interface FileInfoJson { 29 : 30 : /** 31 : * Computes the list of modified files for a given change and patchset against the parent commit. 32 : * 33 : * @param change a Gerrit change. 34 : * @param patchSet a single revision of the change. 35 : * @return a mapping of the file paths to their related diff information. 36 : */ 37 : default Map<String, FileInfo> getFileInfoMap(Change change, PatchSet patchSet) 38 : throws ResourceConflictException, PatchListNotAvailableException { 39 103 : return getFileInfoMap(change, patchSet.commitId(), null); 40 : } 41 : 42 : /** 43 : * Computes the list of modified files for a given change and patchset against its parent. For 44 : * merge commits, callers can use 0, 1, 2, etc... to choose a specific parent. The first parent is 45 : * 0. 46 : * 47 : * @param change a Gerrit change. 48 : * @param objectId a commit SHA-1 identifying a patchset commit. 49 : * @param parentNum 1-based integer identifying the parent number used for comparison. If zero, 50 : * the only parent will be used or the auto-merge if {@code newCommit} is a merge commit. 51 : * @return a mapping of the file paths to their related diff information. 52 : */ 53 : default Map<String, FileInfo> getFileInfoMap(Change change, ObjectId objectId, int parentNum) 54 : throws ResourceConflictException, PatchListNotAvailableException { 55 5 : return getFileInfoMap(change.getProject(), objectId, parentNum); 56 : } 57 : 58 : /** 59 : * Computes the list of modified files for a given change and patchset identified by its {@code 60 : * objectId} against a specified base patchset. 61 : * 62 : * @param change a Gerrit change. 63 : * @param objectId a commit SHA-1 identifying a patchset commit. 64 : * @param base a base patchset to compare the commit identified by {@code objectId} against. 65 : * @return a mapping of the file paths to their related diff information. 66 : */ 67 : Map<String, FileInfo> getFileInfoMap(Change change, ObjectId objectId, @Nullable PatchSet base) 68 : throws ResourceConflictException, PatchListNotAvailableException; 69 : 70 : /** 71 : * Computes the list of modified files for a given project and commit against its parent. For 72 : * merge commits, callers can use 0, 1, 2, etc... to choose a specific parent. The first parent is 73 : * 0. A value of -1 for parent can be passed to use the default base commit, which is the only 74 : * parent for commits having only one parent, or the auto-merge otherwise. 75 : * 76 : * @param project a project identifying a repository. 77 : * @param objectId a commit SHA-1 identifying a patchset commit. 78 : * @param parentNum 1-based integer identifying the parent number used for comparison. If zero, 79 : * the only parent will be used or the auto-merge if {@code newCommit} is a merge commit. 80 : * @return a mapping of the file paths to their related diff information. 81 : */ 82 : Map<String, FileInfo> getFileInfoMap(Project.NameKey project, ObjectId objectId, int parentNum) 83 : throws ResourceConflictException, PatchListNotAvailableException; 84 : }