From a5dee1c125737cce7a83a052b4f9d84eb48d62d1 Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Thu, 1 Mar 2018 14:24:16 -0800 Subject: [PATCH] Teach UploadPack "thin-pack" in "fetch" Add support for the "thin-pack" parameter in the "fetch" command in the fetch-pack/upload-pack protocol v2. Change-Id: I39a37b2b66a16929137d35c718a3acf2afb6b0b5 Signed-off-by: Jonathan Tan --- .../jgit/transport/UploadPackTest.java | 31 +++++++++++++++++++ .../eclipse/jgit/transport/UploadPack.java | 2 ++ 2 files changed, 33 insertions(+) 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 69d3af53f..b83cf1fb7 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 @@ -13,6 +13,7 @@ import java.util.HashMap; import java.util.Map; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.io.StringWriter; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.internal.storage.dfs.DfsGarbageCollector; @@ -750,6 +751,36 @@ public class UploadPackTest { assertTrue(client.hasObject(barChild.toObjectId())); } + @Test + public void testV2FetchThinPack() throws Exception { + String commonInBlob = "abcdefghijklmnopqrstuvwxyz"; + + RevBlob parentBlob = remote.blob(commonInBlob + "a"); + RevCommit parent = remote.commit(remote.tree(remote.file("foo", parentBlob))); + RevBlob childBlob = remote.blob(commonInBlob + "b"); + RevCommit child = remote.commit(remote.tree(remote.file("foo", childBlob)), parent); + remote.update("branch1", child); + + // Pretend that we have parent to get a thin pack based on it. + ByteArrayInputStream recvStream = uploadPackV2( + "command=fetch\n", + PacketLineIn.DELIM, + "want " + child.toObjectId().getName() + "\n", + "have " + parent.toObjectId().getName() + "\n", + "thin-pack\n", + "done\n", + PacketLineIn.END); + PacketLineIn pckIn = new PacketLineIn(recvStream); + + assertThat(pckIn.readString(), is("packfile")); + + // Verify that we received a thin pack by trying to apply it + // against the client repo, which does not have parent. + thrown.expect(IOException.class); + thrown.expectMessage("pack has unresolved deltas"); + parsePack(recvStream); + } + private static class RejectAllRefFilter implements RefFilter { @Override public Map filter(Map refs) { 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 931062c0b..ecafc638d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -954,6 +954,8 @@ public class UploadPack { peerHas.add(ObjectId.fromString(line.substring(5))); } else if (line.equals("done")) { doneReceived = true; + } else if (line.equals(OPTION_THIN_PACK)) { + options.add(OPTION_THIN_PACK); } // else ignore it }