diff options
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java | 85 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java | 17 |
2 files changed, 100 insertions, 2 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java index 260130b2bd..9b090e8949 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java @@ -14,9 +14,11 @@ import static org.junit.Assert.fail; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.InputStream; import java.io.StringWriter; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -30,6 +32,7 @@ import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.internal.storage.dfs.DfsGarbageCollector; import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription; import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository; +import org.eclipse.jgit.internal.storage.file.PackLock; import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.lib.NullProgressMonitor; import org.eclipse.jgit.lib.ObjectId; @@ -65,7 +68,7 @@ public class UploadPackTest { private TestProtocol<Object> testProtocol; - private Object ctx = new Object(); + private final Object ctx = new Object(); private InMemoryRepository server; @@ -2110,4 +2113,84 @@ public class UploadPackTest { return new HashMap<>(); } } + + @Test + public void testSingleBranchCloneTagChain() throws Exception { + RevBlob blob0 = remote.blob("Initial content of first file"); + RevBlob blob1 = remote.blob("Second file content"); + RevCommit commit0 = remote + .commit(remote.tree(remote.file("prvni.txt", blob0))); + RevCommit commit1 = remote + .commit(remote.tree(remote.file("druhy.txt", blob1)), commit0); + remote.update("master", commit1); + + RevTag heavyTag1 = remote.tag("commitTagRing", commit0); + remote.getRevWalk().parseHeaders(heavyTag1); + RevTag heavyTag2 = remote.tag("middleTagRing", heavyTag1); + remote.lightweightTag("refTagRing", heavyTag2); + + UploadPack uploadPack = new UploadPack(remote.getRepository()); + + ByteArrayOutputStream cli = new ByteArrayOutputStream(); + PacketLineOut clientWant = new PacketLineOut(cli); + clientWant.writeString("want " + commit1.name() + + " multi_ack_detailed include-tag thin-pack ofs-delta agent=tempo/pflaska"); + clientWant.end(); + clientWant.writeString("done\n"); + + try (ByteArrayOutputStream serverResponse = new ByteArrayOutputStream()) { + + uploadPack.setPreUploadHook(new PreUploadHook() { + @Override + public void onBeginNegotiateRound(UploadPack up, + Collection<? extends ObjectId> wants, int cntOffered) + throws ServiceMayNotContinueException { + // Do nothing. + } + + @Override + public void onEndNegotiateRound(UploadPack up, + Collection<? extends ObjectId> wants, int cntCommon, + int cntNotFound, boolean ready) + throws ServiceMayNotContinueException { + // Do nothing. + } + + @Override + public void onSendPack(UploadPack up, + Collection<? extends ObjectId> wants, + Collection<? extends ObjectId> haves) + throws ServiceMayNotContinueException { + // collect pack data + serverResponse.reset(); + } + }); + uploadPack.upload(new ByteArrayInputStream(cli.toByteArray()), + serverResponse, System.err); + InputStream packReceived = new ByteArrayInputStream( + serverResponse.toByteArray()); + PackLock lock = null; + try (ObjectInserter ins = client.newObjectInserter()) { + PackParser parser = ins.newPackParser(packReceived); + parser.setAllowThin(true); + parser.setLockMessage("receive-tag-chain"); + ProgressMonitor mlc = NullProgressMonitor.INSTANCE; + lock = parser.parse(mlc, mlc); + ins.flush(); + } finally { + if (lock != null) { + lock.unlock(); + } + } + InMemoryRepository.MemObjDatabase objDb = client + .getObjectDatabase(); + assertTrue(objDb.has(blob0.toObjectId())); + assertTrue(objDb.has(blob1.toObjectId())); + assertTrue(objDb.has(commit0.toObjectId())); + assertTrue(objDb.has(commit1.toObjectId())); + assertTrue(objDb.has(heavyTag1.toObjectId())); + assertTrue(objDb.has(heavyTag2.toObjectId())); + } + } + } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java index 9278f42adf..17632c10a7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -2219,8 +2219,11 @@ public class UploadPack { if (peeledId == null || objectId == null) continue; + objectId = ref.getObjectId(); if (pw.willInclude(peeledId) && !pw.willInclude(objectId)) { - pw.addObject(rw.parseAny(objectId)); + RevObject o = rw.parseAny(objectId); + addTagChain(o, pw); + pw.addObject(o); } } } @@ -2253,6 +2256,18 @@ public class UploadPack { } } + private void addTagChain( + RevObject o, PackWriter pw) throws IOException { + while (Constants.OBJ_TAG == o.getType()) { + RevTag t = (RevTag) o; + o = t.getObject(); + if (o.getType() == Constants.OBJ_TAG && !pw.willInclude(o.getId())) { + walk.parseBody(o); + pw.addObject(o); + } + } + } + private static class ResponseBufferedOutputStream extends OutputStream { private final OutputStream rawOut; |