]> source.dussan.org Git - jgit.git/commitdiff
Respond with shallow-info before wanted-refs 68/127368/1
authorJonathan Tan <jonathantanmy@google.com>
Mon, 13 Aug 2018 23:57:25 +0000 (16:57 -0700)
committerJonathan Tan <jonathantanmy@google.com>
Mon, 13 Aug 2018 23:57:25 +0000 (16:57 -0700)
When fetching with protocol v2, git expects the shallow-info section to
appear before wanted-refs if both appear in the response. Teach
UploadPack to do this.

Change-Id: Ie26a91edcce5d27a1d727d7fba5c30e1144e118b
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

index 7ef713bf45159b20f4f7a9ed0b241e03d2734222..9c43c0b0a44c095f36b7976e5059f36683b4885c 100644 (file)
@@ -1367,13 +1367,13 @@ public class UploadPackTest {
                        PacketLineIn.END);
                PacketLineIn pckIn = new PacketLineIn(recvStream);
 
-               // wanted-refs appears first, then shallow-info.
-               assertThat(pckIn.readString(), is("wanted-refs"));
-               assertThat(pckIn.readString(), is(child.toObjectId().getName() + " refs/heads/branch1"));
-               assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM));
+               // shallow-info appears first, then wanted-refs.
                assertThat(pckIn.readString(), is("shallow-info"));
                assertThat(pckIn.readString(), is("shallow " + child.toObjectId().getName()));
                assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM));
+               assertThat(pckIn.readString(), is("wanted-refs"));
+               assertThat(pckIn.readString(), is(child.toObjectId().getName() + " refs/heads/branch1"));
+               assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM));
                assertThat(pckIn.readString(), is("packfile"));
                parsePack(recvStream);
                assertTrue(client.hasObject(child.toObjectId()));
index c093e8b1db7e43516ae17241e96d07ddc99ffd47..3ad350d0dba110b636f889e92b85e910662ab469 100644 (file)
@@ -1083,18 +1083,6 @@ public class UploadPack {
                }
 
                if (doneReceived || okToGiveUp()) {
-                       if (!wantedRefs.isEmpty()) {
-                               if (sectionSent) {
-                                       pckOut.writeDelim();
-                               }
-                               pckOut.writeString("wanted-refs\n"); //$NON-NLS-1$
-                               for (Map.Entry<String, ObjectId> entry : wantedRefs.entrySet()) {
-                                       pckOut.writeString(entry.getValue().getName() + ' ' +
-                                                       entry.getKey() + '\n');
-                               }
-                               sectionSent = true;
-                       }
-
                        if (shallowCommits != null) {
                                if (sectionSent)
                                        pckOut.writeDelim();
@@ -1108,6 +1096,18 @@ public class UploadPack {
                                sectionSent = true;
                        }
 
+                       if (!wantedRefs.isEmpty()) {
+                               if (sectionSent) {
+                                       pckOut.writeDelim();
+                               }
+                               pckOut.writeString("wanted-refs\n"); //$NON-NLS-1$
+                               for (Map.Entry<String, ObjectId> entry : wantedRefs.entrySet()) {
+                                       pckOut.writeString(entry.getValue().getName() + ' ' +
+                                                       entry.getKey() + '\n');
+                               }
+                               sectionSent = true;
+                       }
+
                        if (sectionSent)
                                pckOut.writeDelim();
                        pckOut.writeString("packfile\n"); //$NON-NLS-1$