From 75b07036928f4ef73e9a217bd7c898457e9c7120 Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Thu, 22 Feb 2018 10:24:19 -0800 Subject: PacketLineIn, PacketLineOut: Add support for delim-pkt Most pkt-lines (data-pkts) have the form pkt-len pkt-payload where pkt-len is a string of 4 hexadecimal digits representing the size in bytes of the pkt-line. Since this size includes the size of the pkt-len, no data-pkt has a length less than 4. A pkt-line with a length field less than 4 can thus be used for other purposes. In Git protocol v1, the only such pkt-line was flush-pkt = "0000" which was used to mark the end of a stream. Protocol v2 (see Documentation/technical/protocol-v2.txt in git.git) introduces a second special pkt-line type: delim-pkt = "0001" used to mark the end of a section within a stream, for example to separate capabilities from the content of a command. [jn: split out from a larger patch that made use of this support] Change-Id: I10e7824fa24ed74c4f45624bd490bba978cf5c34 Signed-off-by: Jonathan Tan Signed-off-by: Jonathan Nieder --- .../org/eclipse/jgit/transport/PacketLineInTest.java | 18 +++++++----------- .../org/eclipse/jgit/transport/PacketLineOutTest.java | 6 ++++++ 2 files changed, 13 insertions(+), 11 deletions(-) (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit') diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineInTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineInTest.java index 13fc68d8c8..982bae8394 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineInTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineInTest.java @@ -115,17 +115,6 @@ public class PacketLineInTest { } } - @Test - public void testReadString_Len0001() { - init("0001"); - try { - in.readString(); - fail("incorrectly accepted invalid packet header"); - } catch (IOException e) { - assertEquals("Invalid packet line header: 0001", e.getMessage()); - } - } - @Test public void testReadString_Len0002() { init("0002"); @@ -164,6 +153,13 @@ public class PacketLineInTest { assertEOF(); } + @Test + public void testReadString_Delim() throws IOException { + init("0001"); + assertSame(PacketLineIn.DELIM, in.readString()); + assertEOF(); + } + // readStringNoLF @Test diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineOutTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineOutTest.java index eca54756b1..dd9a0d3bb5 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineOutTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineOutTest.java @@ -113,6 +113,12 @@ public class PacketLineOutTest { assertEquals(1, flushCnt[0]); } + @Test + public void testWriteDelim() throws IOException { + out.writeDelim(); + assertBuffer("0001"); + } + // writePacket @Test -- cgit v1.2.3