Browse Source

Use one ObjectReader for WalkFetchConnection

Instead of creating new ObjectReader for each walker, use one for
the entire connection and delegate reads through it.

Change-Id: I7f0a2ec8c9fe60b095a7be77dc423a2ff8b443a3
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
stable-0.9
Shawn O. Pearce 15 years ago
parent
commit
d6e975f71b
  1. 38
      org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java

38
org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java

@ -70,6 +70,7 @@ import org.eclipse.jgit.lib.MutableObjectId;
import org.eclipse.jgit.lib.ObjectChecker; import org.eclipse.jgit.lib.ObjectChecker;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectInserter; import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.ProgressMonitor; import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
@ -181,11 +182,15 @@ class WalkFetchConnection extends BaseFetchConnection {
/** Inserter to write objects onto {@link #local}. */ /** Inserter to write objects onto {@link #local}. */
private final ObjectInserter inserter; private final ObjectInserter inserter;
/** Inserter to read objects from {@link #local}. */
private final ObjectReader reader;
WalkFetchConnection(final WalkTransport t, final WalkRemoteObjectDatabase w) { WalkFetchConnection(final WalkTransport t, final WalkRemoteObjectDatabase w) {
Transport wt = (Transport)t; Transport wt = (Transport)t;
local = wt.local; local = wt.local;
objCheck = wt.isCheckFetchedObjects() ? new ObjectChecker() : null; objCheck = wt.isCheckFetchedObjects() ? new ObjectChecker() : null;
inserter = local.newObjectInserter(); inserter = local.newObjectInserter();
reader = local.newObjectReader();
remotes = new ArrayList<WalkRemoteObjectDatabase>(); remotes = new ArrayList<WalkRemoteObjectDatabase>();
remotes.add(w); remotes.add(w);
@ -202,9 +207,9 @@ class WalkFetchConnection extends BaseFetchConnection {
fetchErrors = new HashMap<ObjectId, List<Throwable>>(); fetchErrors = new HashMap<ObjectId, List<Throwable>>();
packLocks = new ArrayList<PackLock>(4); packLocks = new ArrayList<PackLock>(4);
revWalk = new RevWalk(local); revWalk = new RevWalk(reader);
revWalk.setRetainBody(false); revWalk.setRetainBody(false);
treeWalk = new TreeWalk(local); treeWalk = new TreeWalk(reader);
COMPLETE = revWalk.newFlag("COMPLETE"); COMPLETE = revWalk.newFlag("COMPLETE");
IN_WORK_QUEUE = revWalk.newFlag("IN_WORK_QUEUE"); IN_WORK_QUEUE = revWalk.newFlag("IN_WORK_QUEUE");
LOCALLY_SEEN = revWalk.newFlag("LOCALLY_SEEN"); LOCALLY_SEEN = revWalk.newFlag("LOCALLY_SEEN");
@ -243,6 +248,7 @@ class WalkFetchConnection extends BaseFetchConnection {
@Override @Override
public void close() { public void close() {
inserter.release(); inserter.release();
reader.release();
for (final RemotePack p : unfetchedPacks) { for (final RemotePack p : unfetchedPacks) {
if (p.tmpIdx != null) if (p.tmpIdx != null)
p.tmpIdx.delete(); p.tmpIdx.delete();
@ -314,10 +320,17 @@ class WalkFetchConnection extends BaseFetchConnection {
} }
private void processBlob(final RevObject obj) throws TransportException { private void processBlob(final RevObject obj) throws TransportException {
if (!local.hasObject(obj)) try {
throw new TransportException(MessageFormat.format(JGitText.get().cannotReadBlob, obj.name()), if (reader.has(obj, Constants.OBJ_BLOB))
new MissingObjectException(obj, Constants.TYPE_BLOB)); obj.add(COMPLETE);
obj.add(COMPLETE); else
throw new TransportException(MessageFormat.format(JGitText
.get().cannotReadBlob, obj.name()),
new MissingObjectException(obj, Constants.TYPE_BLOB));
} catch (IOException error) {
throw new TransportException(MessageFormat.format(
JGitText.get().cannotReadBlob, obj.name()), error);
}
} }
private void processTree(final RevObject obj) throws TransportException { private void processTree(final RevObject obj) throws TransportException {
@ -374,7 +387,7 @@ class WalkFetchConnection extends BaseFetchConnection {
private void downloadObject(final ProgressMonitor pm, final AnyObjectId id) private void downloadObject(final ProgressMonitor pm, final AnyObjectId id)
throws TransportException { throws TransportException {
if (local.hasObject(id)) if (alreadyHave(id))
return; return;
for (;;) { for (;;) {
@ -461,6 +474,15 @@ class WalkFetchConnection extends BaseFetchConnection {
} }
} }
private boolean alreadyHave(final AnyObjectId id) throws TransportException {
try {
return reader.has(id);
} catch (IOException error) {
throw new TransportException(MessageFormat.format(
JGitText.get().cannotReadObject, id.name()), error);
}
}
private boolean downloadPackedObject(final ProgressMonitor monitor, private boolean downloadPackedObject(final ProgressMonitor monitor,
final AnyObjectId id) throws TransportException { final AnyObjectId id) throws TransportException {
// Search for the object in a remote pack whose index we have, // Search for the object in a remote pack whose index we have,
@ -522,7 +544,7 @@ class WalkFetchConnection extends BaseFetchConnection {
packItr.remove(); packItr.remove();
} }
if (!local.hasObject(id)) { if (!alreadyHave(id)) {
// What the hell? This pack claimed to have // What the hell? This pack claimed to have
// the object, but after indexing we didn't // the object, but after indexing we didn't
// actually find it in the pack. // actually find it in the pack.

Loading…
Cancel
Save