From 186a0deb988a2436ce39b167407435f37eff5f84 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 30 Jun 2008 23:03:58 -0400 Subject: [PATCH] Correct thin pack completion in IndexPack to handle some bundles Recently I saw a bundle with a chain of deltas to base objects as A->B->C, where A was the delta depending on the base B. In this pack all of the objects used OBJ_REF_DELTA to link to their base and C was not in the pack (it was assumed to be in the repository). Because of the ordering of the ObjectIds for B and C jgit tried to resolve A's delta base by pulling from the repository, as B was not found in the pack file. The reason B was not found was because it was waiting in the queue (to be processed next) and we did not know what B's ObjectId was. By skipping objects whose ObjectLoader's aren't found we should be able to resolve those objects later when their delta base does get resolved in this pack. However by the end of of this loop we must have no more objects depending on something by ObjectId, as that is an indication that the local repository is missing the objects we must have to complete this thin pack. Signed-off-by: Shawn O. Pearce Signed-off-by: Robin Rosenberg --- .../src/org/spearce/jgit/transport/IndexPack.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/IndexPack.java b/org.spearce.jgit/src/org/spearce/jgit/transport/IndexPack.java index 24a05779..29d99db8 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/transport/IndexPack.java +++ b/org.spearce.jgit/src/org/spearce/jgit/transport/IndexPack.java @@ -55,6 +55,7 @@ import java.util.zip.Deflater; import java.util.zip.Inflater; import org.spearce.jgit.errors.CorruptObjectException; +import org.spearce.jgit.errors.MissingObjectException; import org.spearce.jgit.lib.BinaryDelta; import org.spearce.jgit.lib.Constants; import org.spearce.jgit.lib.InflaterCache; @@ -399,9 +400,10 @@ public class IndexPack { final Deflater def = new Deflater(Deflater.DEFAULT_COMPRESSION, false); long end = packOut.length() - 20; - while (!baseById.isEmpty()) { - final ObjectId baseId = baseById.keySet().iterator().next(); + for (final ObjectId baseId : new ArrayList(baseById.keySet())) { final ObjectLoader ldr = repo.openObject(baseId); + if (ldr == null) + continue; final byte[] data = ldr.getBytes(); final int typeCode = ldr.getType(); final PackedObjectInfo oe; @@ -419,6 +421,11 @@ public class IndexPack { } def.end(); + if (!baseById.isEmpty()) { + final ObjectId need = baseById.keySet().iterator().next(); + throw new MissingObjectException(need, "delta base"); + } + fixHeaderFooter(); } -- 2.11.4.GIT