Browse Source

Download pack-*.idx to /tmp if not on local filesystem

If the destination repository doesn't use an ObjectDirectory to
store its objects, we can't download to the object directory.
Instead pull the pack-*.idx files down to temporary files in the
JVM's default temporary directory.

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

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

@ -70,6 +70,7 @@ import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.MutableObjectId; import org.eclipse.jgit.lib.MutableObjectId;
import org.eclipse.jgit.lib.ObjectChecker; import org.eclipse.jgit.lib.ObjectChecker;
import org.eclipse.jgit.lib.ObjectDirectory;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.PackIndex; import org.eclipse.jgit.lib.PackIndex;
import org.eclipse.jgit.lib.PackLock; import org.eclipse.jgit.lib.PackLock;
@ -240,8 +241,10 @@ class WalkFetchConnection extends BaseFetchConnection {
@Override @Override
public void close() { public void close() {
for (final RemotePack p : unfetchedPacks) for (final RemotePack p : unfetchedPacks) {
if (p.tmpIdx != null)
p.tmpIdx.delete(); p.tmpIdx.delete();
}
for (final WalkRemoteObjectDatabase r : remotes) for (final WalkRemoteObjectDatabase r : remotes)
r.close(); r.close();
} }
@ -512,6 +515,7 @@ class WalkFetchConnection extends BaseFetchConnection {
// it failed the index and pack are unusable and we // it failed the index and pack are unusable and we
// shouldn't consult them again. // shouldn't consult them again.
// //
if (pack.tmpIdx != null)
pack.tmpIdx.delete(); pack.tmpIdx.delete();
packItr.remove(); packItr.remove();
} }
@ -788,12 +792,11 @@ class WalkFetchConnection extends BaseFetchConnection {
final String idxName; final String idxName;
final File tmpIdx; File tmpIdx;
PackIndex index; PackIndex index;
RemotePack(final WalkRemoteObjectDatabase c, final String pn) { RemotePack(final WalkRemoteObjectDatabase c, final String pn) {
final File objdir = local.getObjectsDirectory();
connection = c; connection = c;
packName = pn; packName = pn;
idxName = packName.substring(0, packName.length() - 5) + ".idx"; idxName = packName.substring(0, packName.length() - 5) + ".idx";
@ -803,13 +806,19 @@ class WalkFetchConnection extends BaseFetchConnection {
tn = tn.substring(5); tn = tn.substring(5);
if (tn.endsWith(".idx")) if (tn.endsWith(".idx"))
tn = tn.substring(0, tn.length() - 4); tn = tn.substring(0, tn.length() - 4);
tmpIdx = new File(objdir, "walk-" + tn + ".walkidx");
if (local.getObjectDatabase() instanceof ObjectDirectory) {
tmpIdx = new File(((ObjectDirectory) local.getObjectDatabase())
.getDirectory(), "walk-" + tn + ".walkidx");
}
} }
void openIndex(final ProgressMonitor pm) throws IOException { void openIndex(final ProgressMonitor pm) throws IOException {
if (index != null) if (index != null)
return; return;
if (tmpIdx.isFile()) { if (tmpIdx == null)
tmpIdx = File.createTempFile("jgit-walk-", ".idx");
else if (tmpIdx.isFile()) {
try { try {
index = PackIndex.open(tmpIdx); index = PackIndex.open(tmpIdx);
return; return;

Loading…
Cancel
Save