{"thread":{"id":"19665","subject":"[JGIT PATCH 1/7] Move hex parsing functions to RawParseUtil, accept upper case","startedAt":"2009-06-04T21:43:56Z","lastAt":"2009-06-15T14:36:04Z","messageCount":9,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":7},"messages":[{"id":"115450","messageId":"1244151843-26954-1-git-send-email-spearce@spearce.org","threadId":"19665","inReplyTo":null,"subject":"[JGIT PATCH 0/7] Misc. transport cleanup","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-06-04T21:43:56Z","receivedAt":"2009-06-04T21:43:56Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"After the dicussions with Jakub Narebski I realized we aren't as\nlenient in parsing hex strings as C Git is.  So make it so.\n\nI also added some tests for the lower level parts of the native\nprotocol, the pkt-line format.  Testing is still far from complete\nin this area of the code, but we're slightly better now.\n\nShawn O. Pearce (7):\n  Move hex parsing functions to RawParseUtil, accept upper case\n  Disambiguate pkt-line \"0000\" from \"0004\"\n  Move PacketLineIn hex parsing to RawParseUtils\n  Add tests for RawParseUtil's hex string parsing\n  Add tests for PacketLineIn\n  Add tests for PacketLineOut\n  Add tests for SideBandOutputStream\n\n .../tst/org/spearce/jgit/lib/T0001_ObjectId.java   |   10 +-\n .../spearce/jgit/transport/PacketLineInTest.java   |  262 ++++++++++++++++++++\n .../spearce/jgit/transport/PacketLineOutTest.java  |  175 +++++++++++++\n .../jgit/transport/SideBandOutputStreamTest.java   |  146 +++++++++++\n .../jgit/util/RawParseUtils_HexParseTest.java      |  158 ++++++++++++\n .../org/spearce/jgit/lib/AbbreviatedObjectId.java  |    8 +-\n .../src/org/spearce/jgit/lib/AnyObjectId.java      |   36 ---\n .../src/org/spearce/jgit/lib/MutableObjectId.java  |   11 +-\n .../src/org/spearce/jgit/lib/ObjectId.java         |   19 +-\n .../spearce/jgit/transport/BasePackConnection.java |    5 +-\n .../jgit/transport/BasePackPushConnection.java     |    2 +-\n .../org/spearce/jgit/transport/DaemonClient.java   |    5 +-\n .../org/spearce/jgit/transport/PacketLineIn.java   |   44 +---\n .../org/spearce/jgit/transport/ReceivePack.java    |    6 +-\n .../src/org/spearce/jgit/transport/UploadPack.java |    4 +-\n .../src/org/spearce/jgit/util/RawParseUtils.java   |  110 ++++++++-\n 16 files changed, 893 insertions(+), 108 deletions(-)\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/transport/PacketLineInTest.java\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/transport/PacketLineOutTest.java\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/transport/SideBandOutputStreamTest.java\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/util/RawParseUtils_HexParseTest.java\n"},{"id":"115447","messageId":"1244151843-26954-2-git-send-email-spearce@spearce.org","threadId":"19665","inReplyTo":"1244151843-26954-1-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 1/7] Move hex parsing functions to RawParseUtil, accept upper case","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-06-04T21:43:57Z","receivedAt":"2009-06-04T21:43:57Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"This way we can reuse them beyond just the ObjectId family of classes.\n\nWe also now accept upper case hex digits in object ids.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../tst/org/spearce/jgit/lib/T0001_ObjectId.java   |   10 ++-\n .../org/spearce/jgit/lib/AbbreviatedObjectId.java  |    8 +-\n .../src/org/spearce/jgit/lib/AnyObjectId.java      |   36 ---------\n .../src/org/spearce/jgit/lib/MutableObjectId.java  |   11 ++-\n .../src/org/spearce/jgit/lib/ObjectId.java         |   19 +++--\n .../src/org/spearce/jgit/util/RawParseUtils.java   |   80 ++++++++++++++++++--\n 6 files changed, 101 insertions(+), 63 deletions(-)\n\ndiff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0001_ObjectId.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0001_ObjectId.java\nindex 4c03667..7a53925 100644\n--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0001_ObjectId.java\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0001_ObjectId.java\n@@ -74,8 +74,8 @@ assertFalse(\"39 digits is not an id\", ObjectId\n \t\t\t\t.isId(\"def4c620bc3713bb1bb26b808ec9312548e7394\"));\n \t}\n \n-\tpublic void test007_notIsId() {\n-\t\tassertFalse(\"uppercase is not accepted\", ObjectId\n+\tpublic void test007_isId() {\n+\t\tassertTrue(\"uppercase is accepted\", ObjectId\n \t\t\t\t.isId(\"Def4c620bc3713bb1bb26b808ec9312548e73946\"));\n \t}\n \n@@ -94,4 +94,10 @@ public void test010_toString() {\n \t\tfinal String x = \"0000000000000000000000000000000000000000\";\n \t\tassertEquals(x, ObjectId.toString(null));\n \t}\n+\n+\tpublic void test011_toString() {\n+\t\tfinal String x = \"0123456789ABCDEFabcdef1234567890abcdefAB\";\n+\t\tfinal ObjectId oid = ObjectId.fromString(x);\n+\t\tassertEquals(x.toLowerCase(), oid.name());\n+\t}\n }\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/AbbreviatedObjectId.java b/org.spearce.jgit/src/org/spearce/jgit/lib/AbbreviatedObjectId.java\nindex ed03fb5..1706e88 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/AbbreviatedObjectId.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/AbbreviatedObjectId.java\n@@ -40,6 +40,7 @@\n import java.io.UnsupportedEncodingException;\n \n import org.spearce.jgit.util.NB;\n+import org.spearce.jgit.util.RawParseUtils;\n \n /**\n  * A prefix abbreviation of an {@link ObjectId}.\n@@ -107,15 +108,12 @@ private static final AbbreviatedObjectId fromHexString(final byte[] bs,\n \n \tprivate static final int hexUInt32(final byte[] bs, int p, final int end) {\n \t\tif (8 <= end - p)\n-\t\t\treturn AnyObjectId.hexUInt32(bs, p);\n+\t\t\treturn RawParseUtils.parseHexInt32(bs, p);\n \n \t\tint r = 0, n = 0;\n \t\twhile (n < 8 && p < end) {\n-\t\t\tfinal int v = AnyObjectId.fromhex[bs[p++]];\n-\t\t\tif (v < 0)\n-\t\t\t\tthrow new ArrayIndexOutOfBoundsException();\n \t\t\tr <<= 4;\n-\t\t\tr |= v;\n+\t\t\tr |= RawParseUtils.parseHexInt4(bs[p++]);\n \t\t\tn++;\n \t\t}\n \t\treturn r << (8 - n) * 4;\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/AnyObjectId.java b/org.spearce.jgit/src/org/spearce/jgit/lib/AnyObjectId.java\nindex acb3cb5..0df2768 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/AnyObjectId.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/AnyObjectId.java\n@@ -41,7 +41,6 @@\n import java.io.OutputStream;\n import java.io.Writer;\n import java.nio.ByteBuffer;\n-import java.util.Arrays;\n \n import org.spearce.jgit.util.NB;\n \n@@ -57,16 +56,7 @@\n \n \tstatic final int STR_LEN = RAW_LEN * 2;\n \n-\tstatic final byte fromhex[];\n-\n \tstatic {\n-\t\tfromhex = new byte['f' + 1];\n-\t\tArrays.fill(fromhex, (byte) -1);\n-\t\tfor (char i = '0'; i <= '9'; i++)\n-\t\t\tfromhex[i] = (byte) (i - '0');\n-\t\tfor (char i = 'a'; i <= 'f'; i++)\n-\t\t\tfromhex[i] = (byte) ((i - 'a') + 10);\n-\n \t\tif (RAW_LEN != 20)\n \t\t\tthrow new LinkageError(\"ObjectId expects\"\n \t\t\t\t\t+ \" Constants.OBJECT_ID_LENGTH = 20; it is \" + RAW_LEN\n@@ -100,32 +90,6 @@ public static boolean equals(final AnyObjectId firstObjectId,\n \t\t\t\t&& firstObjectId.w1 == secondObjectId.w1;\n \t}\n \n-\tstatic final int hexUInt32(final byte[] bs, final int p) {\n-\t\tint r = fromhex[bs[p]] << 4;\n-\n-\t\tr |= fromhex[bs[p + 1]];\n-\t\tr <<= 4;\n-\n-\t\tr |= fromhex[bs[p + 2]];\n-\t\tr <<= 4;\n-\n-\t\tr |= fromhex[bs[p + 3]];\n-\t\tr <<= 4;\n-\n-\t\tr |= fromhex[bs[p + 4]];\n-\t\tr <<= 4;\n-\n-\t\tr |= fromhex[bs[p + 5]];\n-\t\tr <<= 4;\n-\n-\t\tr |= fromhex[bs[p + 6]];\n-\n-\t\tfinal int last = fromhex[bs[p + 7]];\n-\t\tif (r < 0 || last < 0)\n-\t\t\tthrow new ArrayIndexOutOfBoundsException();\n-\t\treturn (r << 4) | last;\n-\t}\n-\n \tint w1;\n \n \tint w2;\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/MutableObjectId.java b/org.spearce.jgit/src/org/spearce/jgit/lib/MutableObjectId.java\nindex fadebab..805f328 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/MutableObjectId.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/MutableObjectId.java\n@@ -40,6 +40,7 @@\n import java.io.UnsupportedEncodingException;\n \n import org.spearce.jgit.util.NB;\n+import org.spearce.jgit.util.RawParseUtils;\n \n /**\n  * A mutable SHA-1 abstraction.\n@@ -159,11 +160,11 @@ public void fromString(final String str) {\n \n \tprivate void fromHexString(final byte[] bs, int p) {\n \t\ttry {\n-\t\t\tw1 = hexUInt32(bs, p);\n-\t\t\tw2 = hexUInt32(bs, p + 8);\n-\t\t\tw3 = hexUInt32(bs, p + 16);\n-\t\t\tw4 = hexUInt32(bs, p + 24);\n-\t\t\tw5 = hexUInt32(bs, p + 32);\n+\t\t\tw1 = RawParseUtils.parseHexInt32(bs, p);\n+\t\t\tw2 = RawParseUtils.parseHexInt32(bs, p + 8);\n+\t\t\tw3 = RawParseUtils.parseHexInt32(bs, p + 16);\n+\t\t\tw4 = RawParseUtils.parseHexInt32(bs, p + 24);\n+\t\t\tw5 = RawParseUtils.parseHexInt32(bs, p + 32);\n \t\t} catch (ArrayIndexOutOfBoundsException e1) {\n \t\t\ttry {\n \t\t\t\tfinal String str = new String(bs, p, STR_LEN, \"US-ASCII\");\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectId.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectId.java\nindex fde209b..cdd523f 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectId.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectId.java\n@@ -41,6 +41,7 @@\n import java.io.UnsupportedEncodingException;\n \n import org.spearce.jgit.util.NB;\n+import org.spearce.jgit.util.RawParseUtils;\n \n /**\n  * A SHA-1 abstraction.\n@@ -74,12 +75,12 @@ public static final ObjectId zeroId() {\n \t * @return true if the string can converted into an ObjectId.\n \t */\n \tpublic static final boolean isId(final String id) {\n-\t\tif (id.length() != 2 * Constants.OBJECT_ID_LENGTH)\n+\t\tif (id.length() != STR_LEN)\n \t\t\treturn false;\n \t\ttry {\n-\t\t\tfor (int k = id.length() - 1; k >= 0; k--)\n-\t\t\t\tif (fromhex[id.charAt(k)] < 0)\n-\t\t\t\t\treturn false;\n+\t\t\tfor (int i = 0; i < STR_LEN; i++) {\n+\t\t\t\tRawParseUtils.parseHexInt4((byte) id.charAt(i));\n+\t\t\t}\n \t\t\treturn true;\n \t\t} catch (ArrayIndexOutOfBoundsException e) {\n \t\t\treturn false;\n@@ -222,11 +223,11 @@ public static final ObjectId fromString(final String str) {\n \n \tprivate static final ObjectId fromHexString(final byte[] bs, int p) {\n \t\ttry {\n-\t\t\tfinal int a = hexUInt32(bs, p);\n-\t\t\tfinal int b = hexUInt32(bs, p + 8);\n-\t\t\tfinal int c = hexUInt32(bs, p + 16);\n-\t\t\tfinal int d = hexUInt32(bs, p + 24);\n-\t\t\tfinal int e = hexUInt32(bs, p + 32);\n+\t\t\tfinal int a = RawParseUtils.parseHexInt32(bs, p);\n+\t\t\tfinal int b = RawParseUtils.parseHexInt32(bs, p + 8);\n+\t\t\tfinal int c = RawParseUtils.parseHexInt32(bs, p + 16);\n+\t\t\tfinal int d = RawParseUtils.parseHexInt32(bs, p + 24);\n+\t\t\tfinal int e = RawParseUtils.parseHexInt32(bs, p + 32);\n \t\t\treturn new ObjectId(a, b, c, d, e);\n \t\t} catch (ArrayIndexOutOfBoundsException e1) {\n \t\t\ttry {\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java b/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java\nindex 79ebe41..0554acb 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java\n@@ -54,13 +54,24 @@\n \n /** Handy utility functions to parse raw object contents. */\n public final class RawParseUtils {\n-\tprivate static final byte[] digits;\n+\tprivate static final byte[] digits10;\n+\n+\tprivate static final byte[] digits16;\n \n \tstatic {\n-\t\tdigits = new byte['9' + 1];\n-\t\tArrays.fill(digits, (byte) -1);\n+\t\tdigits10 = new byte['9' + 1];\n+\t\tArrays.fill(digits10, (byte) -1);\n+\t\tfor (char i = '0'; i <= '9'; i++)\n+\t\t\tdigits10[i] = (byte) (i - '0');\n+\n+\t\tdigits16 = new byte['f' + 1];\n+\t\tArrays.fill(digits16, (byte) -1);\n \t\tfor (char i = '0'; i <= '9'; i++)\n-\t\t\tdigits[i] = (byte) (i - '0');\n+\t\t\tdigits16[i] = (byte) (i - '0');\n+\t\tfor (char i = 'a'; i <= 'f'; i++)\n+\t\t\tdigits16[i] = (byte) ((i - 'a') + 10);\n+\t\tfor (char i = 'A'; i <= 'F'; i++)\n+\t\t\tdigits16[i] = (byte) ((i - 'A') + 10);\n \t}\n \n \t/**\n@@ -175,7 +186,7 @@ public static final int parseBase10(final byte[] b, int ptr,\n \t\t\t}\n \n \t\t\twhile (ptr < sz) {\n-\t\t\t\tfinal byte v = digits[b[ptr]];\n+\t\t\t\tfinal byte v = digits10[b[ptr]];\n \t\t\t\tif (v < 0)\n \t\t\t\t\tbreak;\n \t\t\t\tr = (r * 10) + v;\n@@ -229,7 +240,7 @@ public static final long parseLongBase10(final byte[] b, int ptr,\n \t\t\t}\n \n \t\t\twhile (ptr < sz) {\n-\t\t\t\tfinal byte v = digits[b[ptr]];\n+\t\t\t\tfinal byte v = digits10[b[ptr]];\n \t\t\t\tif (v < 0)\n \t\t\t\t\tbreak;\n \t\t\t\tr = (r * 10) + v;\n@@ -244,6 +255,63 @@ public static final long parseLongBase10(final byte[] b, int ptr,\n \t}\n \n \t/**\n+\t * Parse 8 character base 16 (hex) formatted string to unsigned integer.\n+\t * <p>\n+\t * The number is read in network byte order, that is, most significant\n+\t * nybble first.\n+\t *\n+\t * @param bs\n+\t *            buffer to parse digits from; positions {@code [p, p+8)} will\n+\t *            be parsed.\n+\t * @param p\n+\t *            first position within the buffer to parse.\n+\t * @return the integer value.\n+\t * @throws ArrayIndexOutOfBoundsException\n+\t *             if the string is not hex formatted.\n+\t */\n+\tpublic static final int parseHexInt32(final byte[] bs, final int p) {\n+\t\tint r = digits16[bs[p]] << 4;\n+\n+\t\tr |= digits16[bs[p + 1]];\n+\t\tr <<= 4;\n+\n+\t\tr |= digits16[bs[p + 2]];\n+\t\tr <<= 4;\n+\n+\t\tr |= digits16[bs[p + 3]];\n+\t\tr <<= 4;\n+\n+\t\tr |= digits16[bs[p + 4]];\n+\t\tr <<= 4;\n+\n+\t\tr |= digits16[bs[p + 5]];\n+\t\tr <<= 4;\n+\n+\t\tr |= digits16[bs[p + 6]];\n+\n+\t\tfinal int last = digits16[bs[p + 7]];\n+\t\tif (r < 0 || last < 0)\n+\t\t\tthrow new ArrayIndexOutOfBoundsException();\n+\t\treturn (r << 4) | last;\n+\t}\n+\n+\t/**\n+\t * Parse a single hex digit to its numeric value (0-15).\n+\t *\n+\t * @param digit\n+\t *            hex character to parse.\n+\t * @return numeric value, in the range 0-15.\n+\t * @throws ArrayIndexOutOfBoundsException\n+\t *             if the input digit is not a valid hex digit.\n+\t */\n+\tpublic static final int parseHexInt4(final byte digit) {\n+\t\tfinal byte r = digits16[digit];\n+\t\tif (r < 0)\n+\t\t\tthrow new ArrayIndexOutOfBoundsException();\n+\t\treturn r;\n+\t}\n+\n+\t/**\n \t * Parse a Git style timezone string.\n \t * <p>\n \t * The sequence \"-0315\" will be parsed as the numeric value -195, as the\n-- \n1.6.3.1.333.g3ebba7\n"},{"id":"115448","messageId":"1244151843-26954-3-git-send-email-spearce@spearce.org","threadId":"19665","inReplyTo":"1244151843-26954-2-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 2/7] Disambiguate pkt-line \"0000\" from \"0004\"","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-06-04T21:43:58Z","receivedAt":"2009-06-04T21:43:58Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"The pkt-line length includes its own 4 bytes.  So \"0000\" is the\nmagic flush/end marker used as part of the protocols based upon\npkt-line, while \"0004\" indicates a packet of 0 bytes, but not a\nflush/end marker.\n\nCurrently there is no need for this distinction in the code, as\nthe protocol never sends an empty packet, but it reduces the risk\nthat in the future a \"0004\" packet is misread as a \"0000\" flush.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../spearce/jgit/transport/BasePackConnection.java |    5 ++---\n .../jgit/transport/BasePackPushConnection.java     |    2 +-\n .../org/spearce/jgit/transport/DaemonClient.java   |    5 +----\n .../org/spearce/jgit/transport/PacketLineIn.java   |   18 +++++++++---------\n .../org/spearce/jgit/transport/ReceivePack.java    |    6 +++---\n .../src/org/spearce/jgit/transport/UploadPack.java |    4 ++--\n 6 files changed, 18 insertions(+), 22 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackConnection.java b/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackConnection.java\nindex c6440c7..0382d2b 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackConnection.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackConnection.java\n@@ -140,6 +140,8 @@ private void readAdvertisedRefsImpl() throws IOException {\n \t\t\t\t\tthrow noRepository();\n \t\t\t\tthrow eof;\n \t\t\t}\n+\t\t\tif (line == PacketLineIn.END)\n+\t\t\t\tbreak;\n \n \t\t\tif (avail.isEmpty()) {\n \t\t\t\tfinal int nul = line.indexOf('\\0');\n@@ -152,9 +154,6 @@ private void readAdvertisedRefsImpl() throws IOException {\n \t\t\t\t}\n \t\t\t}\n \n-\t\t\tif (line.length() == 0)\n-\t\t\t\tbreak;\n-\n \t\t\tString name = line.substring(41, line.length());\n \t\t\tif (avail.isEmpty() && name.equals(\"capabilities^{}\")) {\n \t\t\t\t// special line from git-receive-pack to show\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackPushConnection.java b/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackPushConnection.java\nindex 1117109..712d3c0 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackPushConnection.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackPushConnection.java\n@@ -225,7 +225,7 @@ private void readStatusReport(final Map<String, RemoteRefUpdate> refUpdates)\n \t\t\t\t\t\t\t+ unpackStatus);\n \n \t\tString refLine;\n-\t\twhile ((refLine = pckIn.readString()).length() > 0) {\n+\t\twhile ((refLine = pckIn.readString()) != PacketLineIn.END) {\n \t\t\tboolean ok = false;\n \t\t\tint refNameEnd = -1;\n \t\t\tif (refLine.startsWith(\"ok \")) {\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/DaemonClient.java b/org.spearce.jgit/src/org/spearce/jgit/transport/DaemonClient.java\nindex 636cf22..e80d86b 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/transport/DaemonClient.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/DaemonClient.java\n@@ -85,10 +85,7 @@ void execute(final InputStream in, final OutputStream out)\n \t\trawIn = in;\n \t\trawOut = out;\n \n-\t\tString cmd = new PacketLineIn(rawIn).readStringNoLF();\n-\t\tif (cmd == null || cmd.length() == 0)\n-\t\t\treturn;\n-\n+\t\tString cmd = new PacketLineIn(rawIn).readStringRaw();\n \t\tfinal int nul = cmd.indexOf('\\0');\n \t\tif (nul >= 0) {\n \t\t\t// Newer clients hide a \"host\" header behind this byte.\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/PacketLineIn.java b/org.spearce.jgit/src/org/spearce/jgit/transport/PacketLineIn.java\nindex ef218be..92c7009 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/transport/PacketLineIn.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/PacketLineIn.java\n@@ -50,6 +50,7 @@\n import org.spearce.jgit.util.RawParseUtils;\n \n class PacketLineIn {\n+\tstatic final String END = new String(\"\") /* must not string pool */;\n \tprivate static final byte fromhex[];\n \n \tstatic {\n@@ -101,20 +102,23 @@ AckNackResult readACK(final MutableObjectId returnedId) throws IOException {\n \tString readString() throws IOException {\n \t\tint len = readLength();\n \t\tif (len == 0)\n-\t\t\treturn \"\";\n+\t\t\treturn END;\n \n-\t\tlen -= 5; // length header (4 bytes) and trailing LF.\n+\t\tlen -= 4; // length header (4 bytes)\n+\t\tif (len == 0)\n+\t\t\treturn \"\";\n \n \t\tfinal byte[] raw = new byte[len];\n \t\tNB.readFully(in, raw, 0, len);\n-\t\treadLF();\n+\t\tif (raw[len - 1] == '\\n')\n+\t\t\tlen--;\n \t\treturn RawParseUtils.decode(Constants.CHARSET, raw, 0, len);\n \t}\n \n-\tString readStringNoLF() throws IOException {\n+\tString readStringRaw() throws IOException {\n \t\tint len = readLength();\n \t\tif (len == 0)\n-\t\t\treturn \"\";\n+\t\t\treturn END;\n \n \t\tlen -= 4; // length header (4 bytes)\n \n@@ -123,10 +127,6 @@ String readStringNoLF() throws IOException {\n \t\treturn RawParseUtils.decode(Constants.CHARSET, raw, 0, len);\n \t}\n \n-\tprivate void readLF() throws IOException {\n-\t\tif (in.read() != '\\n')\n-\t\t\tthrow new IOException(\"Protocol error: expected LF\");\n-\t}\n \n \tint readLength() throws IOException {\n \t\tNB.readFully(in, lenbuffer, 0, 4);\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java b/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java\nindex eaa1016..abaf876 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java\n@@ -506,12 +506,14 @@ private void recvCommands() throws IOException {\n \t\tfor (;;) {\n \t\t\tString line;\n \t\t\ttry {\n-\t\t\t\tline = pckIn.readStringNoLF();\n+\t\t\t\tline = pckIn.readStringRaw();\n \t\t\t} catch (EOFException eof) {\n \t\t\t\tif (commands.isEmpty())\n \t\t\t\t\treturn;\n \t\t\t\tthrow eof;\n \t\t\t}\n+\t\t\tif (line == PacketLineIn.END)\n+\t\t\t\tbreak;\n \n \t\t\tif (commands.isEmpty()) {\n \t\t\t\tfinal int nul = line.indexOf('\\0');\n@@ -522,8 +524,6 @@ private void recvCommands() throws IOException {\n \t\t\t\t}\n \t\t\t}\n \n-\t\t\tif (line.length() == 0)\n-\t\t\t\tbreak;\n \t\t\tif (line.length() < 83) {\n \t\t\t\tfinal String m = \"error: invalid protocol: wanted 'old new ref'\";\n \t\t\t\tsendError(m);\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/UploadPack.java b/org.spearce.jgit/src/org/spearce/jgit/transport/UploadPack.java\nindex 45d57b3..53fbce0 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/transport/UploadPack.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/UploadPack.java\n@@ -293,7 +293,7 @@ private void recvWants() throws IOException {\n \t\t\t\tthrow eof;\n \t\t\t}\n \n-\t\t\tif (line.length() == 0)\n+\t\t\tif (line == PacketLineIn.END)\n \t\t\t\tbreak;\n \t\t\tif (!line.startsWith(\"want \") || line.length() < 45)\n \t\t\t\tthrow new PackProtocolException(\"expected want; got \" + line);\n@@ -348,7 +348,7 @@ private void negotiate() throws IOException {\n \t\t\t\tthrow eof;\n \t\t\t}\n \n-\t\t\tif (line.length() == 0) {\n+\t\t\tif (line == PacketLineIn.END) {\n \t\t\t\tif (commonBase.isEmpty() || multiAck)\n \t\t\t\t\tpckOut.writeString(\"NAK\\n\");\n \t\t\t\tpckOut.flush();\n-- \n1.6.3.1.333.g3ebba7\n"},{"id":"115449","messageId":"1244151843-26954-4-git-send-email-spearce@spearce.org","threadId":"19665","inReplyTo":"1244151843-26954-3-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 3/7] Move PacketLineIn hex parsing to RawParseUtils","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-06-04T21:43:59Z","receivedAt":"2009-06-04T21:43:59Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"This way we can reuse the same declaration buffer, and accept\nuppercase digits as well as lowercase digits.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../org/spearce/jgit/transport/PacketLineIn.java   |   26 ++---------------\n .../src/org/spearce/jgit/util/RawParseUtils.java   |   30 ++++++++++++++++++++\n 2 files changed, 33 insertions(+), 23 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/PacketLineIn.java b/org.spearce.jgit/src/org/spearce/jgit/transport/PacketLineIn.java\nindex 92c7009..8d2cd18 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/transport/PacketLineIn.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/PacketLineIn.java\n@@ -40,7 +40,6 @@\n \n import java.io.IOException;\n import java.io.InputStream;\n-import java.util.Arrays;\n \n import org.spearce.jgit.errors.PackProtocolException;\n import org.spearce.jgit.lib.Constants;\n@@ -51,16 +50,6 @@\n \n class PacketLineIn {\n \tstatic final String END = new String(\"\") /* must not string pool */;\n-\tprivate static final byte fromhex[];\n-\n-\tstatic {\n-\t\tfromhex = new byte['f' + 1];\n-\t\tArrays.fill(fromhex, (byte) -1);\n-\t\tfor (char i = '0'; i <= '9'; i++)\n-\t\t\tfromhex[i] = (byte) (i - '0');\n-\t\tfor (char i = 'a'; i <= 'f'; i++)\n-\t\t\tfromhex[i] = (byte) ((i - 'a') + 10);\n-\t}\n \n \tstatic enum AckNackResult {\n \t\t/** NAK */\n@@ -127,22 +116,13 @@ String readStringRaw() throws IOException {\n \t\treturn RawParseUtils.decode(Constants.CHARSET, raw, 0, len);\n \t}\n \n-\n \tint readLength() throws IOException {\n \t\tNB.readFully(in, lenbuffer, 0, 4);\n \t\ttry {\n-\t\t\tint r = fromhex[lenbuffer[0]] << 4;\n-\n-\t\t\tr |= fromhex[lenbuffer[1]];\n-\t\t\tr <<= 4;\n-\n-\t\t\tr |= fromhex[lenbuffer[2]];\n-\t\t\tr <<= 4;\n-\n-\t\t\tr |= fromhex[lenbuffer[3]];\n-\t\t\tif (r < 0)\n+\t\t\tfinal int len = RawParseUtils.parseHexInt16(lenbuffer, 0);\n+\t\t\tif (len != 0 && len < 4)\n \t\t\t\tthrow new ArrayIndexOutOfBoundsException();\n-\t\t\treturn r;\n+\t\t\treturn len;\n \t\t} catch (ArrayIndexOutOfBoundsException err) {\n \t\t\tthrow new IOException(\"Invalid packet line header: \"\n \t\t\t\t\t+ (char) lenbuffer[0] + (char) lenbuffer[1]\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java b/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java\nindex 0554acb..5fb3d27 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java\n@@ -255,6 +255,36 @@ public static final long parseLongBase10(final byte[] b, int ptr,\n \t}\n \n \t/**\n+\t * Parse 4 character base 16 (hex) formatted string to unsigned integer.\n+\t * <p>\n+\t * The number is read in network byte order, that is, most significant\n+\t * nybble first.\n+\t *\n+\t * @param bs\n+\t *            buffer to parse digits from; positions {@code [p, p+4)} will\n+\t *            be parsed.\n+\t * @param p\n+\t *            first position within the buffer to parse.\n+\t * @return the integer value.\n+\t * @throws ArrayIndexOutOfBoundsException\n+\t *             if the string is not hex formatted.\n+\t */\n+\tpublic static final int parseHexInt16(final byte[] bs, final int p) {\n+\t\tint r = digits16[bs[p]] << 4;\n+\n+\t\tr |= digits16[bs[p + 1]];\n+\t\tr <<= 4;\n+\n+\t\tr |= digits16[bs[p + 2]];\n+\t\tr <<= 4;\n+\n+\t\tr |= digits16[bs[p + 3]];\n+\t\tif (r < 0)\n+\t\t\tthrow new ArrayIndexOutOfBoundsException();\n+\t\treturn r;\n+\t}\n+\n+\t/**\n \t * Parse 8 character base 16 (hex) formatted string to unsigned integer.\n \t * <p>\n \t * The number is read in network byte order, that is, most significant\n-- \n1.6.3.1.333.g3ebba7\n"},{"id":"115452","messageId":"1244151843-26954-5-git-send-email-spearce@spearce.org","threadId":"19665","inReplyTo":"1244151843-26954-4-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 4/7] Add tests for RawParseUtil's hex string parsing","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-06-04T21:44:00Z","receivedAt":"2009-06-04T21:44:00Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Signed-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../jgit/util/RawParseUtils_HexParseTest.java      |  158 ++++++++++++++++++++\n 1 files changed, 158 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/util/RawParseUtils_HexParseTest.java\n\ndiff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/util/RawParseUtils_HexParseTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/util/RawParseUtils_HexParseTest.java\nnew file mode 100644\nindex 0000000..0f0ddde\n--- /dev/null\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/util/RawParseUtils_HexParseTest.java\n@@ -0,0 +1,158 @@\n+/*\n+ * Copyright (C) 2009, Google Inc.\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+package org.spearce.jgit.util;\n+\n+import junit.framework.TestCase;\n+\n+import org.spearce.jgit.lib.Constants;\n+\n+public class RawParseUtils_HexParseTest extends TestCase {\n+\tpublic void testInt4_1() {\n+\t\tassertEquals(0, RawParseUtils.parseHexInt4((byte) '0'));\n+\t\tassertEquals(1, RawParseUtils.parseHexInt4((byte) '1'));\n+\t\tassertEquals(2, RawParseUtils.parseHexInt4((byte) '2'));\n+\t\tassertEquals(3, RawParseUtils.parseHexInt4((byte) '3'));\n+\t\tassertEquals(4, RawParseUtils.parseHexInt4((byte) '4'));\n+\t\tassertEquals(5, RawParseUtils.parseHexInt4((byte) '5'));\n+\t\tassertEquals(6, RawParseUtils.parseHexInt4((byte) '6'));\n+\t\tassertEquals(7, RawParseUtils.parseHexInt4((byte) '7'));\n+\t\tassertEquals(8, RawParseUtils.parseHexInt4((byte) '8'));\n+\t\tassertEquals(9, RawParseUtils.parseHexInt4((byte) '9'));\n+\t\tassertEquals(10, RawParseUtils.parseHexInt4((byte) 'a'));\n+\t\tassertEquals(11, RawParseUtils.parseHexInt4((byte) 'b'));\n+\t\tassertEquals(12, RawParseUtils.parseHexInt4((byte) 'c'));\n+\t\tassertEquals(13, RawParseUtils.parseHexInt4((byte) 'd'));\n+\t\tassertEquals(14, RawParseUtils.parseHexInt4((byte) 'e'));\n+\t\tassertEquals(15, RawParseUtils.parseHexInt4((byte) 'f'));\n+\n+\t\tassertEquals(10, RawParseUtils.parseHexInt4((byte) 'A'));\n+\t\tassertEquals(11, RawParseUtils.parseHexInt4((byte) 'B'));\n+\t\tassertEquals(12, RawParseUtils.parseHexInt4((byte) 'C'));\n+\t\tassertEquals(13, RawParseUtils.parseHexInt4((byte) 'D'));\n+\t\tassertEquals(14, RawParseUtils.parseHexInt4((byte) 'E'));\n+\t\tassertEquals(15, RawParseUtils.parseHexInt4((byte) 'F'));\n+\n+\t\tassertNotHex('q');\n+\t\tassertNotHex(' ');\n+\t\tassertNotHex('.');\n+\t}\n+\n+\tprivate static void assertNotHex(final char c) {\n+\t\ttry {\n+\t\t\tRawParseUtils.parseHexInt4((byte) c);\n+\t\t\tfail(\"Incorrectly acccepted \" + c);\n+\t\t} catch (ArrayIndexOutOfBoundsException e) {\n+\t\t\t// pass\n+\t\t}\n+\t}\n+\n+\tpublic void testInt16() {\n+\t\tassertEquals(0x0000, parse16(\"0000\"));\n+\t\tassertEquals(0x0001, parse16(\"0001\"));\n+\t\tassertEquals(0x1234, parse16(\"1234\"));\n+\t\tassertEquals(0xdead, parse16(\"dead\"));\n+\t\tassertEquals(0xBEEF, parse16(\"BEEF\"));\n+\t\tassertEquals(0x4321, parse16(\"4321\"));\n+\t\tassertEquals(0xffff, parse16(\"ffff\"));\n+\n+\t\ttry {\n+\t\t\tparse16(\"noth\");\n+\t\t\tfail(\"Incorrectly acccepted \\\"noth\\\"\");\n+\t\t} catch (ArrayIndexOutOfBoundsException e) {\n+\t\t\t// pass\n+\t\t}\n+\n+\t\ttry {\n+\t\t\tparse16(\"01\");\n+\t\t\tfail(\"Incorrectly acccepted \\\"01\\\"\");\n+\t\t} catch (ArrayIndexOutOfBoundsException e) {\n+\t\t\t// pass\n+\t\t}\n+\n+\t\ttry {\n+\t\t\tparse16(\"000.\");\n+\t\t\tfail(\"Incorrectly acccepted \\\"000.\\\"\");\n+\t\t} catch (ArrayIndexOutOfBoundsException e) {\n+\t\t\t// pass\n+\t\t}\n+\t}\n+\n+\tprivate static int parse16(final String str) {\n+\t\treturn RawParseUtils.parseHexInt16(Constants.encodeASCII(str), 0);\n+\t}\n+\n+\tpublic void testInt32() {\n+\t\tassertEquals(0x00000000, parse32(\"00000000\"));\n+\t\tassertEquals(0x00000001, parse32(\"00000001\"));\n+\t\tassertEquals(0xc0ffEE42, parse32(\"c0ffEE42\"));\n+\t\tassertEquals(0xffffffff, parse32(\"ffffffff\"));\n+\t\tassertEquals(-1, parse32(\"ffffffff\"));\n+\n+\t\ttry {\n+\t\t\tparse32(\"noth\");\n+\t\t\tfail(\"Incorrectly acccepted \\\"noth\\\"\");\n+\t\t} catch (ArrayIndexOutOfBoundsException e) {\n+\t\t\t// pass\n+\t\t}\n+\n+\t\ttry {\n+\t\t\tparse32(\"notahexs\");\n+\t\t\tfail(\"Incorrectly acccepted \\\"notahexs\\\"\");\n+\t\t} catch (ArrayIndexOutOfBoundsException e) {\n+\t\t\t// pass\n+\t\t}\n+\n+\t\ttry {\n+\t\t\tparse32(\"01\");\n+\t\t\tfail(\"Incorrectly acccepted \\\"01\\\"\");\n+\t\t} catch (ArrayIndexOutOfBoundsException e) {\n+\t\t\t// pass\n+\t\t}\n+\n+\t\ttry {\n+\t\t\tparse32(\"0000000.\");\n+\t\t\tfail(\"Incorrectly acccepted \\\"0000000.\\\"\");\n+\t\t} catch (ArrayIndexOutOfBoundsException e) {\n+\t\t\t// pass\n+\t\t}\n+\t}\n+\n+\tprivate static int parse32(final String str) {\n+\t\treturn RawParseUtils.parseHexInt32(Constants.encodeASCII(str), 0);\n+\t}\n+}\n-- \n1.6.3.1.333.g3ebba7\n"},{"id":"115451","messageId":"1244151843-26954-6-git-send-email-spearce@spearce.org","threadId":"19665","inReplyTo":"1244151843-26954-5-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 5/7] Add tests for PacketLineIn","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-06-04T21:44:01Z","receivedAt":"2009-06-04T21:44:01Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Signed-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../spearce/jgit/transport/PacketLineInTest.java   |  262 ++++++++++++++++++++\n 1 files changed, 262 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/transport/PacketLineInTest.java\n\ndiff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/transport/PacketLineInTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/transport/PacketLineInTest.java\nnew file mode 100644\nindex 0000000..b9ab50e\n--- /dev/null\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/transport/PacketLineInTest.java\n@@ -0,0 +1,262 @@\n+/*\n+ * Copyright (C) 2009, Google Inc.\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+package org.spearce.jgit.transport;\n+\n+import java.io.ByteArrayInputStream;\n+import java.io.IOException;\n+\n+import junit.framework.TestCase;\n+\n+import org.spearce.jgit.lib.Constants;\n+import org.spearce.jgit.lib.MutableObjectId;\n+import org.spearce.jgit.lib.ObjectId;\n+\n+// Note, test vectors created with:\n+//\n+// perl -e 'printf \"%4.4x%s\\n\", 4+length($ARGV[0]),$ARGV[0]'\n+\n+public class PacketLineInTest extends TestCase {\n+\tprivate ByteArrayInputStream rawIn;\n+\n+\tprivate PacketLineIn in;\n+\n+\t// readString\n+\n+\tpublic void testReadString1() throws IOException {\n+\t\tinit(\"0006a\\n0007bc\\n\");\n+\t\tassertEquals(\"a\", in.readString());\n+\t\tassertEquals(\"bc\", in.readString());\n+\t\tassertEOF();\n+\t}\n+\n+\tpublic void testReadString2() throws IOException {\n+\t\tinit(\"0032want fcfcfb1fd94829c1a1704f894fc111d14770d34e\\n\");\n+\t\tfinal String act = in.readString();\n+\t\tassertEquals(\"want fcfcfb1fd94829c1a1704f894fc111d14770d34e\", act);\n+\t\tassertEOF();\n+\t}\n+\n+\tpublic void testReadString4() throws IOException {\n+\t\tinit(\"0005a0006bc\");\n+\t\tassertEquals(\"a\", in.readString());\n+\t\tassertEquals(\"bc\", in.readString());\n+\t\tassertEOF();\n+\t}\n+\n+\tpublic void testReadString5() throws IOException {\n+\t\t// accept both upper and lower case\n+\t\tinit(\"000Fhi i am a s\");\n+\t\tassertEquals(\"hi i am a s\", in.readString());\n+\t\tassertEOF();\n+\n+\t\tinit(\"000fhi i am a s\");\n+\t\tassertEquals(\"hi i am a s\", in.readString());\n+\t\tassertEOF();\n+\t}\n+\n+\tpublic void testReadString_LenHELO() {\n+\t\tinit(\"HELO\");\n+\t\ttry {\n+\t\t\tin.readString();\n+\t\t\tfail(\"incorrectly accepted invalid packet header\");\n+\t\t} catch (IOException e) {\n+\t\t\tassertEquals(\"Invalid packet line header: HELO\", e.getMessage());\n+\t\t}\n+\t}\n+\n+\tpublic void testReadString_Len0001() {\n+\t\tinit(\"0001\");\n+\t\ttry {\n+\t\t\tin.readString();\n+\t\t\tfail(\"incorrectly accepted invalid packet header\");\n+\t\t} catch (IOException e) {\n+\t\t\tassertEquals(\"Invalid packet line header: 0001\", e.getMessage());\n+\t\t}\n+\t}\n+\n+\tpublic void testReadString_Len0002() {\n+\t\tinit(\"0002\");\n+\t\ttry {\n+\t\t\tin.readString();\n+\t\t\tfail(\"incorrectly accepted invalid packet header\");\n+\t\t} catch (IOException e) {\n+\t\t\tassertEquals(\"Invalid packet line header: 0002\", e.getMessage());\n+\t\t}\n+\t}\n+\n+\tpublic void testReadString_Len0003() {\n+\t\tinit(\"0003\");\n+\t\ttry {\n+\t\t\tin.readString();\n+\t\t\tfail(\"incorrectly accepted invalid packet header\");\n+\t\t} catch (IOException e) {\n+\t\t\tassertEquals(\"Invalid packet line header: 0003\", e.getMessage());\n+\t\t}\n+\t}\n+\n+\tpublic void testReadString_Len0004() throws IOException {\n+\t\tinit(\"0004\");\n+\t\tfinal String act = in.readString();\n+\t\tassertEquals(\"\", act);\n+\t\tassertNotSame(PacketLineIn.END, act);\n+\t\tassertEOF();\n+\t}\n+\n+\tpublic void testReadString_End() throws IOException {\n+\t\tinit(\"0000\");\n+\t\tassertSame(PacketLineIn.END, in.readString());\n+\t\tassertEOF();\n+\t}\n+\n+\t// readStringNoLF\n+\n+\tpublic void testReadStringRaw1() throws IOException {\n+\t\tinit(\"0005a0006bc\");\n+\t\tassertEquals(\"a\", in.readStringRaw());\n+\t\tassertEquals(\"bc\", in.readStringRaw());\n+\t\tassertEOF();\n+\t}\n+\n+\tpublic void testReadStringRaw2() throws IOException {\n+\t\tinit(\"0031want fcfcfb1fd94829c1a1704f894fc111d14770d34e\");\n+\t\tfinal String act = in.readStringRaw();\n+\t\tassertEquals(\"want fcfcfb1fd94829c1a1704f894fc111d14770d34e\", act);\n+\t\tassertEOF();\n+\t}\n+\n+\tpublic void testReadStringRaw3() throws IOException {\n+\t\tinit(\"0004\");\n+\t\tfinal String act = in.readStringRaw();\n+\t\tassertEquals(\"\", act);\n+\t\tassertNotSame(PacketLineIn.END, act);\n+\t\tassertEOF();\n+\t}\n+\n+\tpublic void testReadStringRaw_End() throws IOException {\n+\t\tinit(\"0000\");\n+\t\tassertSame(PacketLineIn.END, in.readStringRaw());\n+\t\tassertEOF();\n+\t}\n+\n+\tpublic void testReadStringRaw4() {\n+\t\tinit(\"HELO\");\n+\t\ttry {\n+\t\t\tin.readStringRaw();\n+\t\t\tfail(\"incorrectly accepted invalid packet header\");\n+\t\t} catch (IOException e) {\n+\t\t\tassertEquals(\"Invalid packet line header: HELO\", e.getMessage());\n+\t\t}\n+\t}\n+\n+\t// readACK\n+\n+\tpublic void testReadACK_NAK() throws IOException {\n+\t\tfinal ObjectId expid = ObjectId\n+\t\t\t\t.fromString(\"fcfcfb1fd94829c1a1704f894fc111d14770d34e\");\n+\t\tfinal MutableObjectId actid = new MutableObjectId();\n+\t\tactid.fromString(expid.name());\n+\n+\t\tinit(\"0008NAK\\n\");\n+\t\tassertSame(PacketLineIn.AckNackResult.NAK, in.readACK(actid));\n+\t\tassertTrue(actid.equals(expid));\n+\t\tassertEOF();\n+\t}\n+\n+\tpublic void testReadACK_ACK1() throws IOException {\n+\t\tfinal ObjectId expid = ObjectId\n+\t\t\t\t.fromString(\"fcfcfb1fd94829c1a1704f894fc111d14770d34e\");\n+\t\tfinal MutableObjectId actid = new MutableObjectId();\n+\n+\t\tinit(\"0031ACK fcfcfb1fd94829c1a1704f894fc111d14770d34e\\n\");\n+\t\tassertSame(PacketLineIn.AckNackResult.ACK, in.readACK(actid));\n+\t\tassertTrue(actid.equals(expid));\n+\t\tassertEOF();\n+\t}\n+\n+\tpublic void testReadACK_ACKcontinue1() throws IOException {\n+\t\tfinal ObjectId expid = ObjectId\n+\t\t\t\t.fromString(\"fcfcfb1fd94829c1a1704f894fc111d14770d34e\");\n+\t\tfinal MutableObjectId actid = new MutableObjectId();\n+\n+\t\tinit(\"003aACK fcfcfb1fd94829c1a1704f894fc111d14770d34e continue\\n\");\n+\t\tassertSame(PacketLineIn.AckNackResult.ACK_CONTINUE, in.readACK(actid));\n+\t\tassertTrue(actid.equals(expid));\n+\t\tassertEOF();\n+\t}\n+\n+\tpublic void testReadACK_Invalid1() {\n+\t\tinit(\"HELO\");\n+\t\ttry {\n+\t\t\tin.readACK(new MutableObjectId());\n+\t\t\tfail(\"incorrectly accepted invalid packet header\");\n+\t\t} catch (IOException e) {\n+\t\t\tassertEquals(\"Invalid packet line header: HELO\", e.getMessage());\n+\t\t}\n+\t}\n+\n+\tpublic void testReadACK_Invalid2() {\n+\t\tinit(\"0009HELO\\n\");\n+\t\ttry {\n+\t\t\tin.readACK(new MutableObjectId());\n+\t\t\tfail(\"incorrectly accepted invalid ACK/NAK\");\n+\t\t} catch (IOException e) {\n+\t\t\tassertEquals(\"Expected ACK/NAK, got: HELO\", e.getMessage());\n+\t\t}\n+\t}\n+\n+\tpublic void testReadACK_Invalid3() {\n+\t\tinit(\"0000\");\n+\t\ttry {\n+\t\t\tin.readACK(new MutableObjectId());\n+\t\t\tfail(\"incorrectly accepted no ACK/NAK\");\n+\t\t} catch (IOException e) {\n+\t\t\tassertEquals(\"Expected ACK/NAK, found EOF\", e.getMessage());\n+\t\t}\n+\t}\n+\n+\t// test support\n+\n+\tprivate void init(final String msg) {\n+\t\trawIn = new ByteArrayInputStream(Constants.encodeASCII(msg));\n+\t\tin = new PacketLineIn(rawIn);\n+\t}\n+\n+\tprivate void assertEOF() {\n+\t\tassertEquals(-1, rawIn.read());\n+\t}\n+}\n-- \n1.6.3.1.333.g3ebba7\n"},{"id":"115453","messageId":"1244151843-26954-7-git-send-email-spearce@spearce.org","threadId":"19665","inReplyTo":"1244151843-26954-6-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 6/7] Add tests for PacketLineOut","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-06-04T21:44:02Z","receivedAt":"2009-06-04T21:44:02Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Signed-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../spearce/jgit/transport/PacketLineOutTest.java  |  175 ++++++++++++++++++++\n 1 files changed, 175 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/transport/PacketLineOutTest.java\n\ndiff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/transport/PacketLineOutTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/transport/PacketLineOutTest.java\nnew file mode 100644\nindex 0000000..de0f222\n--- /dev/null\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/transport/PacketLineOutTest.java\n@@ -0,0 +1,175 @@\n+/*\n+ * Copyright (C) 2009, Google Inc.\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+package org.spearce.jgit.transport;\n+\n+import java.io.ByteArrayOutputStream;\n+import java.io.IOException;\n+import java.io.OutputStream;\n+\n+import junit.framework.TestCase;\n+\n+import org.spearce.jgit.lib.Constants;\n+\n+// Note, test vectors created with:\n+//\n+// perl -e 'printf \"%4.4x%s\\n\", 4+length($ARGV[0]),$ARGV[0]'\n+\n+public class PacketLineOutTest extends TestCase {\n+\tprivate ByteArrayOutputStream rawOut;\n+\n+\tprivate PacketLineOut out;\n+\n+\tprotected void setUp() throws Exception {\n+\t\tsuper.setUp();\n+\t\trawOut = new ByteArrayOutputStream();\n+\t\tout = new PacketLineOut(rawOut);\n+\t}\n+\n+\t// writeString\n+\n+\tpublic void testWriteString1() throws IOException {\n+\t\tout.writeString(\"a\");\n+\t\tout.writeString(\"bc\");\n+\t\tassertBuffer(\"0005a0006bc\");\n+\t}\n+\n+\tpublic void testWriteString2() throws IOException {\n+\t\tout.writeString(\"a\\n\");\n+\t\tout.writeString(\"bc\\n\");\n+\t\tassertBuffer(\"0006a\\n0007bc\\n\");\n+\t}\n+\n+\tpublic void testWriteString3() throws IOException {\n+\t\tout.writeString(\"\");\n+\t\tassertBuffer(\"0004\");\n+\t}\n+\n+\t// end\n+\n+\tpublic void testWriteEnd() throws IOException {\n+\t\tfinal int[] flushCnt = new int[1];\n+\t\tfinal OutputStream mockout = new OutputStream() {\n+\t\t\t@Override\n+\t\t\tpublic void write(int arg0) throws IOException {\n+\t\t\t\trawOut.write(arg0);\n+\t\t\t}\n+\n+\t\t\t@Override\n+\t\t\tpublic void flush() throws IOException {\n+\t\t\t\tflushCnt[0]++;\n+\t\t\t}\n+\t\t};\n+\n+\t\tnew PacketLineOut(mockout).end();\n+\t\tassertBuffer(\"0000\");\n+\t\tassertEquals(1, flushCnt[0]);\n+\t}\n+\n+\t// writePacket\n+\n+\tpublic void testWritePacket1() throws IOException {\n+\t\tout.writePacket(new byte[] { 'a' });\n+\t\tassertBuffer(\"0005a\");\n+\t}\n+\n+\tpublic void testWritePacket2() throws IOException {\n+\t\tout.writePacket(new byte[] { 'a', 'b', 'c', 'd' });\n+\t\tassertBuffer(\"0008abcd\");\n+\t}\n+\n+\tpublic void testWritePacket3() throws IOException {\n+\t\tfinal int buflen = SideBandOutputStream.MAX_BUF\n+\t\t\t\t- SideBandOutputStream.HDR_SIZE;\n+\t\tfinal byte[] buf = new byte[buflen];\n+\t\tfor (int i = 0; i < buf.length; i++) {\n+\t\t\tbuf[i] = (byte) i;\n+\t\t}\n+\t\tout.writePacket(buf);\n+\t\tout.flush();\n+\n+\t\tfinal byte[] act = rawOut.toByteArray();\n+\t\tfinal String explen = Integer.toString(buf.length + 4, 16);\n+\t\tassertEquals(4 + buf.length, act.length);\n+\t\tassertEquals(new String(act, 0, 4, \"UTF-8\"), explen);\n+\t\tfor (int i = 0, j = 4; i < buf.length; i++, j++) {\n+\t\t\tassertEquals(buf[i], act[j]);\n+\t\t}\n+\t}\n+\n+\t// writeChannelPacket\n+\n+\tpublic void testWriteChannelPacket1() throws IOException {\n+\t\tout.writeChannelPacket(1, new byte[] { 'a' }, 0, 1);\n+\t\tassertBuffer(\"0006\\001a\");\n+\t}\n+\n+\tpublic void testWriteChannelPacket2() throws IOException {\n+\t\tout.writeChannelPacket(2, new byte[] { 'b' }, 0, 1);\n+\t\tassertBuffer(\"0006\\002b\");\n+\t}\n+\n+\tpublic void testWriteChannelPacket3() throws IOException {\n+\t\tout.writeChannelPacket(3, new byte[] { 'c' }, 0, 1);\n+\t\tassertBuffer(\"0006\\003c\");\n+\t}\n+\n+\t// flush\n+\n+\tpublic void testFlush() throws IOException {\n+\t\tfinal int[] flushCnt = new int[1];\n+\t\tfinal OutputStream mockout = new OutputStream() {\n+\t\t\t@Override\n+\t\t\tpublic void write(int arg0) throws IOException {\n+\t\t\t\tfail(\"should not write\");\n+\t\t\t}\n+\n+\t\t\t@Override\n+\t\t\tpublic void flush() throws IOException {\n+\t\t\t\tflushCnt[0]++;\n+\t\t\t}\n+\t\t};\n+\n+\t\tnew PacketLineOut(mockout).flush();\n+\t\tassertEquals(1, flushCnt[0]);\n+\t}\n+\n+\tprivate void assertBuffer(final String exp) throws IOException {\n+\t\tassertEquals(exp, new String(rawOut.toByteArray(),\n+\t\t\t\tConstants.CHARACTER_ENCODING));\n+\t}\n+}\n-- \n1.6.3.1.333.g3ebba7\n"},{"id":"115454","messageId":"1244151843-26954-8-git-send-email-spearce@spearce.org","threadId":"19665","inReplyTo":"1244151843-26954-7-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 7/7] Add tests for SideBandOutputStream","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-06-04T21:44:03Z","receivedAt":"2009-06-04T21:44:03Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Signed-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../jgit/transport/SideBandOutputStreamTest.java   |  146 ++++++++++++++++++++\n 1 files changed, 146 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/transport/SideBandOutputStreamTest.java\n\ndiff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/transport/SideBandOutputStreamTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/transport/SideBandOutputStreamTest.java\nnew file mode 100644\nindex 0000000..59e55dc\n--- /dev/null\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/transport/SideBandOutputStreamTest.java\n@@ -0,0 +1,146 @@\n+/*\n+ * Copyright (C) 2009, Google Inc.\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+package org.spearce.jgit.transport;\n+\n+import java.io.ByteArrayOutputStream;\n+import java.io.IOException;\n+import java.io.OutputStream;\n+\n+import junit.framework.TestCase;\n+\n+import org.spearce.jgit.lib.Constants;\n+\n+// Note, test vectors created with:\n+//\n+// perl -e 'printf \"%4.4x%s\\n\", 4+length($ARGV[0]),$ARGV[0]'\n+\n+public class SideBandOutputStreamTest extends TestCase {\n+\tprivate ByteArrayOutputStream rawOut;\n+\n+\tprivate PacketLineOut pckOut;\n+\n+\tprotected void setUp() throws Exception {\n+\t\tsuper.setUp();\n+\t\trawOut = new ByteArrayOutputStream();\n+\t\tpckOut = new PacketLineOut(rawOut);\n+\t}\n+\n+\tpublic void testWrite_CH_DATA() throws IOException {\n+\t\tfinal SideBandOutputStream out;\n+\t\tout = new SideBandOutputStream(SideBandOutputStream.CH_DATA, pckOut);\n+\t\tout.write(new byte[] { 'a', 'b', 'c' });\n+\t\tassertBuffer(\"0008\\001abc\");\n+\t}\n+\n+\tpublic void testWrite_CH_PROGRESS() throws IOException {\n+\t\tfinal SideBandOutputStream out;\n+\t\tout = new SideBandOutputStream(SideBandOutputStream.CH_PROGRESS, pckOut);\n+\t\tout.write(new byte[] { 'a', 'b', 'c' });\n+\t\tassertBuffer(\"0008\\002abc\");\n+\t}\n+\n+\tpublic void testWrite_CH_ERROR() throws IOException {\n+\t\tfinal SideBandOutputStream out;\n+\t\tout = new SideBandOutputStream(SideBandOutputStream.CH_ERROR, pckOut);\n+\t\tout.write(new byte[] { 'a', 'b', 'c' });\n+\t\tassertBuffer(\"0008\\003abc\");\n+\t}\n+\n+\tpublic void testWrite_Small() throws IOException {\n+\t\tfinal SideBandOutputStream out;\n+\t\tout = new SideBandOutputStream(SideBandOutputStream.CH_DATA, pckOut);\n+\t\tout.write('a');\n+\t\tout.write('b');\n+\t\tout.write('c');\n+\t\tassertBuffer(\"0006\\001a0006\\001b0006\\001c\");\n+\t}\n+\n+\tpublic void testWrite_Large() throws IOException {\n+\t\tfinal int buflen = SideBandOutputStream.MAX_BUF\n+\t\t\t\t- SideBandOutputStream.HDR_SIZE;\n+\t\tfinal byte[] buf = new byte[buflen];\n+\t\tfor (int i = 0; i < buf.length; i++) {\n+\t\t\tbuf[i] = (byte) i;\n+\t\t}\n+\n+\t\tfinal SideBandOutputStream out;\n+\t\tout = new SideBandOutputStream(SideBandOutputStream.CH_DATA, pckOut);\n+\t\tout.write(buf);\n+\n+\t\tfinal byte[] act = rawOut.toByteArray();\n+\t\tfinal String explen = Integer.toString(buf.length + 5, 16);\n+\t\tassertEquals(5 + buf.length, act.length);\n+\t\tassertEquals(new String(act, 0, 4, \"UTF-8\"), explen);\n+\t\tassertEquals(1, act[4]);\n+\t\tfor (int i = 0, j = 5; i < buf.length; i++, j++) {\n+\t\t\tassertEquals(buf[i], act[j]);\n+\t\t}\n+\t}\n+\n+\tpublic void testFlush() throws IOException {\n+\t\tfinal int[] flushCnt = new int[1];\n+\t\tfinal OutputStream mockout = new OutputStream() {\n+\t\t\t@Override\n+\t\t\tpublic void write(int arg0) throws IOException {\n+\t\t\t\tfail(\"should not write\");\n+\t\t\t}\n+\n+\t\t\t@Override\n+\t\t\tpublic void flush() throws IOException {\n+\t\t\t\tflushCnt[0]++;\n+\t\t\t}\n+\t\t};\n+\n+\t\tnew SideBandOutputStream(SideBandOutputStream.CH_DATA,\n+\t\t\t\tnew PacketLineOut(mockout)).flush();\n+\t\tassertEquals(0, flushCnt[0]);\n+\n+\t\tnew SideBandOutputStream(SideBandOutputStream.CH_ERROR,\n+\t\t\t\tnew PacketLineOut(mockout)).flush();\n+\t\tassertEquals(1, flushCnt[0]);\n+\n+\t\tnew SideBandOutputStream(SideBandOutputStream.CH_PROGRESS,\n+\t\t\t\tnew PacketLineOut(mockout)).flush();\n+\t\tassertEquals(2, flushCnt[0]);\n+\t}\n+\n+\tprivate void assertBuffer(final String exp) throws IOException {\n+\t\tassertEquals(exp, new String(rawOut.toByteArray(),\n+\t\t\t\tConstants.CHARACTER_ENCODING));\n+\t}\n+}\n-- \n1.6.3.1.333.g3ebba7\n"},{"id":"116340","messageId":"20090615143604.GA10817@spearce.org","threadId":"19665","inReplyTo":"1244151843-26954-2-git-send-email-spearce@spearce.org","subject":"Re: [JGIT PATCH 1/7] Move hex parsing functions to RawParseUtil, accept upper case","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-06-15T14:36:04Z","receivedAt":"2009-06-15T14:36:04Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"\"Shawn O. Pearce\" <spearce@spearce.org> wrote:\n> This way we can reuse them beyond just the ObjectId family of classes.\n> \n> We also now accept upper case hex digits in object ids.\n> \n> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>\n> ---\n>  .../tst/org/spearce/jgit/lib/T0001_ObjectId.java   |   10 ++-\n>  .../org/spearce/jgit/lib/AbbreviatedObjectId.java  |    8 +-\n>  .../src/org/spearce/jgit/lib/AnyObjectId.java      |   36 ---------\n>  .../src/org/spearce/jgit/lib/MutableObjectId.java  |   11 ++-\n>  .../src/org/spearce/jgit/lib/ObjectId.java         |   19 +++--\n>  .../src/org/spearce/jgit/util/RawParseUtils.java   |   80 ++++++++++++++++++--\n>  6 files changed, 101 insertions(+), 63 deletions(-)\n\nPing on this 7 patch series?  Looks like it got dropped?  Its the\nlast outstanding current work I have that I think is ready for\nmerging to master.\n \n-- \nShawn.\n"}]}