Fix FilesInCommitCollection when parent = 0

Change Ia3a97599f8 refactored FileInfoJson to have two implementations:
the current one, and another using the new diff cache redesign. The
previous refactoring also modified FilesInCommitCollection to use the
new FileInfoJson API.

The previous implementation allowed passing a value '0' for parentNum to
FilesInCommitCollection, which was not handled in this refactoring. This
change fixes this case in FileInfoJsonOldImpl and adds tests for
FilesInCommitCollection.

Passing a value '0' was not mentioned in the docs, although it was
handled in the code. I modified the docs to include this case.

Change-Id: I65d505e574acbaf64c68f5cc7ec622ae3f2ab923
This commit is contained in:
Youssef Elghareeb
2021-02-08 12:19:27 +01:00
parent d99be5e5cd
commit 8df6d5c36b
7 changed files with 177 additions and 4 deletions

View File

@@ -18,8 +18,10 @@ import com.google.gerrit.extensions.api.changes.ChangeApi;
import com.google.gerrit.extensions.api.changes.CherryPickInput;
import com.google.gerrit.extensions.api.changes.IncludedInInfo;
import com.google.gerrit.extensions.common.CommitInfo;
import com.google.gerrit.extensions.common.FileInfo;
import com.google.gerrit.extensions.restapi.NotImplementedException;
import com.google.gerrit.extensions.restapi.RestApiException;
import java.util.Map;
public interface CommitApi {
CommitInfo get() throws RestApiException;
@@ -28,6 +30,9 @@ public interface CommitApi {
IncludedInInfo includedIn() throws RestApiException;
/** List files in a specific commit against the parent commit. */
Map<String, FileInfo> files(int parentNum) throws RestApiException;
/** A default implementation for source compatibility when adding new methods to the interface. */
class NotImplemented implements CommitApi {
@Override
@@ -44,5 +49,10 @@ public interface CommitApi {
public IncludedInInfo includedIn() throws RestApiException {
throw new NotImplementedException();
}
@Override
public Map<String, FileInfo> files(int parentNum) throws RestApiException {
throw new NotImplementedException();
}
}
}