PatchListLoader: Make readPatchList method public
We would like to write an offline tool to backfill the cache, which helps reduce latency of index upgrades immediately following a cache invalidation. It's much more efficient if we can provide our own Repository in an outer loop rather than having PatchListLoader open one every time. Change-Id: Ib22e0ce4f7fde8197d23986cc9bceb487ac82885
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.patch;
|
package com.google.gerrit.server.patch;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
|
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
|
||||||
|
|
||||||
@@ -112,8 +113,11 @@ public class PatchListLoader implements Callable<PatchList> {
|
|||||||
@Override
|
@Override
|
||||||
public PatchList call() throws IOException,
|
public PatchList call() throws IOException,
|
||||||
PatchListNotAvailableException {
|
PatchListNotAvailableException {
|
||||||
try (Repository repo = repoManager.openRepository(project)) {
|
try (Repository repo = repoManager.openRepository(project);
|
||||||
return readPatchList(key, repo);
|
ObjectInserter ins = newInserter(repo);
|
||||||
|
ObjectReader reader = ins.newReader();
|
||||||
|
RevWalk rw = new RevWalk(reader)) {
|
||||||
|
return readPatchList(repo, rw, ins);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,13 +144,12 @@ public class PatchListLoader implements Callable<PatchList> {
|
|||||||
: new InMemoryInserter(repo);
|
: new InMemoryInserter(repo);
|
||||||
}
|
}
|
||||||
|
|
||||||
private PatchList readPatchList(PatchListKey key, Repository repo)
|
public PatchList readPatchList(Repository repo, RevWalk rw,
|
||||||
throws IOException, PatchListNotAvailableException {
|
ObjectInserter ins) throws IOException, PatchListNotAvailableException {
|
||||||
|
ObjectReader reader = rw.getObjectReader();
|
||||||
|
checkArgument(reader.getCreatedFromInserter() == ins);
|
||||||
RawTextComparator cmp = comparatorFor(key.getWhitespace());
|
RawTextComparator cmp = comparatorFor(key.getWhitespace());
|
||||||
try (ObjectInserter ins = newInserter(repo);
|
try (DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE)) {
|
||||||
ObjectReader reader = ins.newReader();
|
|
||||||
RevWalk rw = new RevWalk(reader);
|
|
||||||
DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE)) {
|
|
||||||
RevCommit b = rw.parseCommit(key.getNewId());
|
RevCommit b = rw.parseCommit(key.getNewId());
|
||||||
RevObject a = aFor(key, repo, rw, ins, b);
|
RevObject a = aFor(key, repo, rw, ins, b);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user