diff options
author | Ronald Bhuleskar <funronald@google.com> | 2021-06-09 15:41:09 -0700 |
---|---|---|
committer | Ronald Bhuleskar <funronald@google.com> | 2021-06-11 12:29:12 -0400 |
commit | 64d0aaa2b624e9c011390d817a6d1fef335bf7b6 (patch) | |
tree | 39f0fcdd11cf31d62f9ce9e202125988e1fcf5c2 /org.eclipse.jgit.test | |
parent | 91a9591253fc157527f8f09b8f5642ec32f5bdde (diff) | |
download | jgit-64d0aaa2b624e9c011390d817a6d1fef335bf7b6.tar.gz jgit-64d0aaa2b624e9c011390d817a6d1fef335bf7b6.zip |
Teach independent negotiation (no pack file) using an option "wait-for-done"
From Git commit 9c1e657a8f:
Currently, the packfile negotiation step within a Git fetch cannot be
done independent of sending the packfile, even though there is at
least one application wherein this is useful - push negotiation.
Therefore, make it possible for this negotiation step to be done
independently.
This feature is for protocol v2 only.
In the protocol, the main hindrance towards independent negotiation is
that the server can unilaterally decide to send the packfile. This is
solved by a "wait-for-done" argument: the server will then wait for
the client to say "done". In practice, the client will never say it;
instead it will cease requests once it is satisfied.
Advertising the server capability option "wait-for-done" is behind the
transport config: uploadpack.advertisewaitfordone, which by default is
false.
Change-Id: I5ebd3e99ad76b8943597216e23ced2ed38eb5224
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java | 102 |
1 files changed, 102 insertions, 0 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 5045e9464e..b0b5f68efa 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 @@ -999,6 +999,108 @@ public class UploadPackTest { } @Test + public void testV2FetchWithoutWaitForDoneReceivesPackfile() + throws Exception { + String commonInBlob = "abcdefghijklmnopqrstuvwxyz"; + + RevBlob parentBlob = remote.blob(commonInBlob + "a"); + RevCommit parent = remote + .commit(remote.tree(remote.file("foo", parentBlob))); + remote.update("branch1", parent); + + RevCommit localParent = null; + RevCommit localChild = null; + try (TestRepository<InMemoryRepository> local = new TestRepository<>( + client)) { + RevBlob localParentBlob = local.blob(commonInBlob + "a"); + localParent = local + .commit(local.tree(local.file("foo", localParentBlob))); + RevBlob localChildBlob = local.blob(commonInBlob + "b"); + localChild = local.commit( + local.tree(local.file("foo", localChildBlob)), localParent); + local.update("branch1", localChild); + } + + ByteArrayInputStream recvStream = uploadPackV2("command=fetch\n", + PacketLineIn.delimiter(), + "have " + localParent.toObjectId().getName() + "\n", + "have " + localChild.toObjectId().getName() + "\n", + PacketLineIn.end()); + PacketLineIn pckIn = new PacketLineIn(recvStream); + assertThat(pckIn.readString(), is("acknowledgments")); + assertThat(Arrays.asList(pckIn.readString()), + hasItems("ACK " + parent.toObjectId().getName())); + assertThat(pckIn.readString(), is("ready")); + assertTrue(PacketLineIn.isDelimiter(pckIn.readString())); + assertThat(pckIn.readString(), is("packfile")); + parsePack(recvStream); + } + + @Test + public void testV2FetchWithWaitForDoneOnlyDoesNegotiation() + throws Exception { + String commonInBlob = "abcdefghijklmnopqrstuvwxyz"; + + RevBlob parentBlob = remote.blob(commonInBlob + "a"); + RevCommit parent = remote + .commit(remote.tree(remote.file("foo", parentBlob))); + remote.update("branch1", parent); + + RevCommit localParent = null; + RevCommit localChild = null; + try (TestRepository<InMemoryRepository> local = new TestRepository<>( + client)) { + RevBlob localParentBlob = local.blob(commonInBlob + "a"); + localParent = local + .commit(local.tree(local.file("foo", localParentBlob))); + RevBlob localChildBlob = local.blob(commonInBlob + "b"); + localChild = local.commit( + local.tree(local.file("foo", localChildBlob)), localParent); + local.update("branch1", localChild); + } + + ByteArrayInputStream recvStream = uploadPackV2("command=fetch\n", + PacketLineIn.delimiter(), "wait-for-done\n", + "have " + localParent.toObjectId().getName() + "\n", + "have " + localChild.toObjectId().getName() + "\n", + PacketLineIn.end()); + PacketLineIn pckIn = new PacketLineIn(recvStream); + assertThat(pckIn.readString(), is("acknowledgments")); + assertThat(Arrays.asList(pckIn.readString()), + hasItems("ACK " + parent.toObjectId().getName())); + assertTrue(PacketLineIn.isEnd(pckIn.readString())); + } + + @Test + public void testV2FetchWithWaitForDoneOnlyDoesNegotiationAndNothingToAck() + throws Exception { + String commonInBlob = "abcdefghijklmnopqrstuvwxyz"; + + RevCommit localParent = null; + RevCommit localChild = null; + try (TestRepository<InMemoryRepository> local = new TestRepository<>( + client)) { + RevBlob localParentBlob = local.blob(commonInBlob + "a"); + localParent = local + .commit(local.tree(local.file("foo", localParentBlob))); + RevBlob localChildBlob = local.blob(commonInBlob + "b"); + localChild = local.commit( + local.tree(local.file("foo", localChildBlob)), localParent); + local.update("branch1", localChild); + } + + ByteArrayInputStream recvStream = uploadPackV2("command=fetch\n", + PacketLineIn.delimiter(), "wait-for-done\n", + "have " + localParent.toObjectId().getName() + "\n", + "have " + localChild.toObjectId().getName() + "\n", + PacketLineIn.end()); + PacketLineIn pckIn = new PacketLineIn(recvStream); + assertThat(pckIn.readString(), is("acknowledgments")); + assertThat(pckIn.readString(), is("NAK")); + assertTrue(PacketLineIn.isEnd(pckIn.readString())); + } + + @Test public void testV2FetchThinPack() throws Exception { String commonInBlob = "abcdefghijklmnopqrstuvwxyz"; |