]> source.dussan.org Git - jgit.git/commitdiff
Merge branch 'stable-5.12' into stable-5.13 46/189746/1
authorMatthias Sohn <matthias.sohn@sap.com>
Tue, 18 Jan 2022 16:51:14 +0000 (17:51 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Tue, 18 Jan 2022 16:51:14 +0000 (17:51 +0100)
* stable-5.12:
  UploadPack v2 protocol: Stop negotiation for orphan refs

Change-Id: Ib43068c32d9cb8effe4b873396391dc3c9197a6e

1  2 
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

index f4bbb4c9f8608787bf92e7065cfb5038840941b3,3958de2d939fcb5d6825c932008dc8bb2b50ba8a..127711ff914dbcb7587ef9bdfe9c2a78a3e89e3a
@@@ -1005,108 -998,61 +1005,163 @@@ public class UploadPackTest 
                assertTrue(client.getObjectDatabase().has(barChild.toObjectId()));
        }
  
 +      @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 testV2FetchServerStopsNegotiationForRefWithoutParents()
+                       throws Exception {
+               RevCommit fooCommit = remote.commit().message("x").create();
+               RevCommit barCommit = remote.commit().message("y").create();
+               remote.update("refs/changes/01/1/1", fooCommit);
+               remote.update("refs/changes/02/2/1", barCommit);
+               ByteArrayInputStream recvStream = uploadPackV2("command=fetch\n",
+                               PacketLineIn.delimiter(),
+                               "want " + fooCommit.toObjectId().getName() + "\n",
+                               "have " + barCommit.toObjectId().getName() + "\n",
+                               PacketLineIn.end());
+               PacketLineIn pckIn = new PacketLineIn(recvStream);
+               assertThat(pckIn.readString(), is("acknowledgments"));
+               assertThat(pckIn.readString(),
+                               is("ACK " + barCommit.toObjectId().getName()));
+               assertThat(pckIn.readString(), is("ready"));
+               assertTrue(PacketLineIn.isDelimiter(pckIn.readString()));
+               assertThat(pckIn.readString(), is("packfile"));
+               parsePack(recvStream);
+               assertTrue(client.getObjectDatabase().has(fooCommit.toObjectId()));
+       }
+       @Test
+       public void testV2FetchServerDoesNotStopNegotiationWhenOneRefWithoutParentAndOtherWithParents()
+                       throws Exception {
+               RevCommit fooCommit = remote.commit().message("x").create();
+               RevCommit barParent = remote.commit().message("y").create();
+               RevCommit barChild = remote.commit().message("y").parent(barParent)
+                               .create();
+               RevCommit fooBarParent = remote.commit().message("z").create();
+               RevCommit fooBarChild = remote.commit().message("y")
+                               .parent(fooBarParent)
+                               .create();
+               remote.update("refs/changes/01/1/1", fooCommit);
+               remote.update("refs/changes/02/2/1", barChild);
+               remote.update("refs/changes/03/3/1", fooBarChild);
+               ByteArrayInputStream recvStream = uploadPackV2("command=fetch\n",
+                               PacketLineIn.delimiter(),
+                               "want " + fooCommit.toObjectId().getName() + "\n",
+                               "want " + barChild.toObjectId().getName() + "\n",
+                               "want " + fooBarChild.toObjectId().getName() + "\n",
+                               "have " + fooBarParent.toObjectId().getName() + "\n",
+                               PacketLineIn.end());
+               PacketLineIn pckIn = new PacketLineIn(recvStream);
+               assertThat(pckIn.readString(), is("acknowledgments"));
+               assertThat(pckIn.readString(),
+                               is("ACK " + fooBarParent.toObjectId().getName()));
+               assertTrue(PacketLineIn.isEnd(pckIn.readString()));
+       }
        @Test
        public void testV2FetchThinPack() throws Exception {
                String commonInBlob = "abcdefghijklmnopqrstuvwxyz";