diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/FileInfoJson.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/FileInfoJson.java index e0591f4683..8e55df549a 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/FileInfoJson.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/FileInfoJson.java @@ -14,8 +14,6 @@ package com.google.gerrit.server.change; -import static com.google.gerrit.server.util.GitUtil.getParent; - import com.google.gerrit.common.Nullable; import com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace; import com.google.gerrit.extensions.common.FileInfo; @@ -23,7 +21,6 @@ import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Patch; import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.client.RevId; -import com.google.gerrit.server.git.GitRepositoryManager; import com.google.gerrit.server.patch.PatchList; import com.google.gerrit.server.patch.PatchListCache; import com.google.gerrit.server.patch.PatchListEntry; @@ -32,24 +29,18 @@ import com.google.gerrit.server.patch.PatchListNotAvailableException; import com.google.inject.Inject; import com.google.inject.Singleton; -import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.eclipse.jgit.lib.ObjectId; -import org.eclipse.jgit.lib.Repository; -import java.io.IOException; import java.util.Map; import java.util.TreeMap; @Singleton public class FileInfoJson { private final PatchListCache patchListCache; - private final GitRepositoryManager repoManager; @Inject FileInfoJson( - PatchListCache patchListCache, - GitRepositoryManager repoManager) { - this.repoManager = repoManager; + PatchListCache patchListCache) { this.patchListCache = patchListCache; } @@ -64,24 +55,19 @@ public class FileInfoJson { ? null : ObjectId.fromString(base.getRevision().get()); ObjectId b = ObjectId.fromString(revision.get()); - return toFileInfoMap(change, a, b); + return toFileInfoMap(change, new PatchListKey(a, b, Whitespace.IGNORE_NONE)); } Map toFileInfoMap(Change change, RevId revision, int parent) - throws RepositoryNotFoundException, IOException, - PatchListNotAvailableException { + throws PatchListNotAvailableException { ObjectId b = ObjectId.fromString(revision.get()); - ObjectId a; - try (Repository git = repoManager.openRepository(change.getProject())) { - a = getParent(git, b, parent); - } - return toFileInfoMap(change, a, b); + return toFileInfoMap(change, + PatchListKey.againstParentNum(parent + 1, b, Whitespace.IGNORE_NONE)); } private Map toFileInfoMap(Change change, - ObjectId a, ObjectId b) throws PatchListNotAvailableException { - PatchList list = patchListCache.get( - new PatchListKey(a, b, Whitespace.IGNORE_NONE), change.getProject()); + PatchListKey key) throws PatchListNotAvailableException { + PatchList list = patchListCache.get(key, change.getProject()); Map files = new TreeMap<>(); for (PatchListEntry e : list.getPatches()) { diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchScriptFactory.java b/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchScriptFactory.java index a7d2523136..754d9950a3 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchScriptFactory.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchScriptFactory.java @@ -15,7 +15,6 @@ package com.google.gerrit.server.patch; import static com.google.common.base.Preconditions.checkArgument; -import static com.google.gerrit.server.util.GitUtil.getParent; import com.google.common.base.Optional; import com.google.gerrit.common.Nullable; @@ -214,8 +213,6 @@ public class PatchScriptFactory implements Callable { bId = toObjectId(psEntityB); if (parentNum < 0) { aId = psEntityA != null ? toObjectId(psEntityA) : null; - } else { - aId = getParent(git, bId, parentNum); } try { @@ -247,7 +244,10 @@ public class PatchScriptFactory implements Callable { } private PatchListKey keyFor(final Whitespace whitespace) { - return new PatchListKey(aId, bId, whitespace); + if (parentNum < 0) { + return new PatchListKey(aId, bId, whitespace); + } + return PatchListKey.againstParentNum(parentNum + 1, bId, whitespace); } private PatchList listFor(final PatchListKey key) diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/util/GitUtil.java b/gerrit-server/src/main/java/com/google/gerrit/server/util/GitUtil.java deleted file mode 100644 index 2d1e1fa4e9..0000000000 --- a/gerrit-server/src/main/java/com/google/gerrit/server/util/GitUtil.java +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 2016 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.gerrit.server.util; - -import org.eclipse.jgit.errors.IncorrectObjectTypeException; -import org.eclipse.jgit.lib.ObjectId; -import org.eclipse.jgit.lib.Repository; -import org.eclipse.jgit.revwalk.RevCommit; -import org.eclipse.jgit.revwalk.RevWalk; - -import java.io.IOException; - -public class GitUtil { - - /** - * @param git - * @param commitId - * @param parentNum - * @return the {@code paretNo} parent of given commit or {@code null} - * when {@code parentNo} exceed number of {@code commitId} parents. - * @throws IncorrectObjectTypeException - * the supplied id is not a commit or an annotated tag. - * @throws IOException - * a pack file or loose object could not be read. - */ - public static RevCommit getParent(Repository git, - ObjectId commitId, int parentNum) throws IOException { - try (RevWalk walk = new RevWalk(git)) { - RevCommit commit = walk.parseCommit(commitId); - if (commit.getParentCount() > parentNum) { - return commit.getParent(parentNum); - } - } - return null; - } - - private GitUtil() { - } -}