Let PatchListLoader always load parent commits
For comparing a commit against one of its parent commits, PatchListLoader accepts PatchListKeys with a parentNum. If parentNum in a PatchListKey is set, PatchListLoader takes care to load the parent commit. However some code paths did not make use of this functionality in PatchListLoader. Instead they loaded the parent commit upfront and then constructed a PatchListKey with 2 commits (the commit and its parent commit) to load the PatchList. Loading the parent commit upfront is unneeded since PatchListLoader knows how to do this. If the parent commit is always loaded by PatchListLoader, the code for loading the parent commit upfront can be deleted. Also for listing files the repository is opened once less now. Change-Id: Ifca30529d25419aaf5af2252f1bcd45ab5dbb853 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -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() {
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user