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 65df6e3c4..22c67c101 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 @@ -2138,7 +2138,14 @@ public class UploadPackTest { PacketLineIn.END); PacketLineIn pckIn = new PacketLineIn(recvStream); - assertThat(pckIn.readString(), is("\001packfile")); + String s; + // When sideband-all is used, object counting happens before + // "packfile" is written, and object counting outputs progress + // in sideband 2. Skip all these lines. + for (s = pckIn.readString(); s.startsWith("\002"); s = pckIn.readString()) { + // do nothing + } + assertThat(s, is("\001packfile")); parsePack(recvStream); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineOut.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineOut.java index b07b6f69d..7f837bb84 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineOut.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineOut.java @@ -74,7 +74,7 @@ public class PacketLineOut { private boolean flushOnEnd; - private boolean useSideband; + private boolean usingSideband; /** * Create a new packet line writer. @@ -100,13 +100,25 @@ public class PacketLineOut { } /** - * When writing packet lines, use the first byte of each non-flush and - * non-delim packet as a sideband designator. - * + * @return whether to add a sideband designator to each non-flush and + * non-delim packet + * @see #setUsingSideband + * @since 5.5 + */ + public boolean isUsingSideband() { + return usingSideband; + } + + /** + * @param value If true, when writing packet lines, add, as the first + * byte, a sideband designator to each non-flush and non-delim + * packet. See pack-protocol.txt and protocol-v2.txt from the Git + * project for more information, specifically the "side-band" and + * "sideband-all" sections. * @since 5.5 */ - public void useSidebandFormat() { - this.useSideband = true; + public void setUsingSideband(boolean value) { + this.usingSideband = value; } /** @@ -151,7 +163,7 @@ public class PacketLineOut { * @since 4.5 */ public void writePacket(byte[] buf, int pos, int len) throws IOException { - if (useSideband) { + if (usingSideband) { formatLength(len + 5); out.write(lenbuffer, 0, 4); out.write(1); 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 c580ed008..2194f2f30 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -1136,7 +1136,7 @@ public class UploadPack { protocolV2Hook.onFetch(req); if (req.getSidebandAll()) { - pckOut.useSidebandFormat(); + pckOut.setUsingSideband(true); } // TODO(ifrade): Refactor to pass around the Request object, instead of @@ -1224,7 +1224,11 @@ public class UploadPack { if (sectionSent) pckOut.writeDelim(); - pckOut.writeString("packfile\n"); //$NON-NLS-1$ + if (!pckOut.isUsingSideband()) { + // sendPack will write "packfile\n" for us if sideband-all is used. + // But sideband-all is not used, so we have to write it ourselves. + pckOut.writeString("packfile\n"); //$NON-NLS-1$ + } sendPack(new PackStatistics.Accumulator(), req, req.getClientCapabilities().contains(OPTION_INCLUDE_TAG) @@ -2293,6 +2297,9 @@ public class UploadPack { } } + if (pckOut.isUsingSideband()) { + pckOut.writeString("packfile\n"); //$NON-NLS-1$ + } pw.writePack(pm, NullProgressMonitor.INSTANCE, packOut); if (msgOut != NullOutputStream.INSTANCE) {