Respond with shallow-info before wanted-refs

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>
This commit is contained in:
Jonathan Tan 2018-08-13 16:57:25 -07:00
parent d1dc49e968
commit 3227348e5e
2 changed files with 16 additions and 16 deletions

View File

@ -1367,13 +1367,13 @@ public void testV2FetchWantRefAndDeepen() throws Exception {
PacketLineIn.END); PacketLineIn.END);
PacketLineIn pckIn = new PacketLineIn(recvStream); PacketLineIn pckIn = new PacketLineIn(recvStream);
// wanted-refs appears first, then shallow-info. // shallow-info appears first, then wanted-refs.
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("shallow-info")); assertThat(pckIn.readString(), is("shallow-info"));
assertThat(pckIn.readString(), is("shallow " + child.toObjectId().getName())); assertThat(pckIn.readString(), is("shallow " + child.toObjectId().getName()));
assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM)); 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")); assertThat(pckIn.readString(), is("packfile"));
parsePack(recvStream); parsePack(recvStream);
assertTrue(client.hasObject(child.toObjectId())); assertTrue(client.hasObject(child.toObjectId()));

View File

@ -1083,18 +1083,6 @@ private void fetchV2() throws IOException {
} }
if (doneReceived || okToGiveUp()) { 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 (shallowCommits != null) {
if (sectionSent) if (sectionSent)
pckOut.writeDelim(); pckOut.writeDelim();
@ -1108,6 +1096,18 @@ private void fetchV2() throws IOException {
sectionSent = true; 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) if (sectionSent)
pckOut.writeDelim(); pckOut.writeDelim();
pckOut.writeString("packfile\n"); //$NON-NLS-1$ pckOut.writeString("packfile\n"); //$NON-NLS-1$