We had the wrong header code in this case, so we didn't parse the length correctly for delta style binary hunks. Without a test case for it we never noticed the problem. Signed-off-by: Shawn O. Pearce <spearce@xxxxxxxxxxx> --- .../tst/org/spearce/jgit/patch/PatchTest.java | 39 +++++++++++++++++++- .../jgit/patch/testParse_GitBinaryDelta.patch | 21 +++++++++++ ...nary.patch => testParse_GitBinaryLiteral.patch} | 0 .../src/org/spearce/jgit/patch/BinaryHunk.java | 2 +- 4 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_GitBinaryDelta.patch rename org.spearce.jgit.test/tst/org/spearce/jgit/patch/{testParse_GitBinary.patch => testParse_GitBinaryLiteral.patch} (100%) diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchTest.java index 2c617d3..8309951 100644 --- a/org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchTest.java +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchTest.java @@ -184,7 +184,7 @@ assertTrue(fh.getNewName().startsWith( assertEquals(272, fh.getHunks().get(0).getOldImage().getStartLine()); } - public void testParse_GitBinary() throws IOException { + public void testParse_GitBinaryLiteral() throws IOException { final Patch p = parseTestPatchFile(); final int[] binsizes = { 359, 393, 372, 404 }; assertEquals(5, p.getFiles().size()); @@ -229,6 +229,43 @@ assertTrue(fh.getNewName().startsWith( assertEquals(272, fh.getHunks().get(0).getOldImage().getStartLine()); } + public void testParse_GitBinaryDelta() throws IOException { + final Patch p = parseTestPatchFile(); + assertEquals(1, p.getFiles().size()); + assertTrue(p.getErrors().isEmpty()); + + final FileHeader fh = p.getFiles().get(0); + assertTrue(fh.getNewName().startsWith("zero.bin")); + assertSame(FileHeader.ChangeType.MODIFY, fh.getChangeType()); + assertSame(FileHeader.PatchType.GIT_BINARY, fh.getPatchType()); + assertSame(FileMode.REGULAR_FILE, fh.getNewMode()); + + assertNotNull(fh.getOldId()); + assertNotNull(fh.getNewId()); + assertEquals("08e7df176454f3ee5eeda13efa0adaa54828dfd8", fh.getOldId() + .name()); + assertEquals("d70d8710b6d32ff844af0ee7c247e4b4b051867f", fh.getNewId() + .name()); + + assertTrue(fh.getHunks().isEmpty()); + assertFalse(fh.hasMetaDataChanges()); + + final BinaryHunk fwd = fh.getForwardBinaryHunk(); + final BinaryHunk rev = fh.getReverseBinaryHunk(); + assertNotNull(fwd); + assertNotNull(rev); + assertEquals(12, fwd.getSize()); + assertEquals(11, rev.getSize()); + + assertSame(fh, fwd.getFileHeader()); + assertSame(fh, rev.getFileHeader()); + + assertSame(BinaryHunk.Type.DELTA_DEFLATED, fwd.getType()); + assertSame(BinaryHunk.Type.DELTA_DEFLATED, rev.getType()); + + assertEquals(496, fh.endOffset); + } + public void testParse_FixNoNewline() throws IOException { final Patch p = parseTestPatchFile(); assertEquals(1, p.getFiles().size()); diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_GitBinaryDelta.patch b/org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_GitBinaryDelta.patch new file mode 100644 index 0000000..5b2c9c6 --- /dev/null +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_GitBinaryDelta.patch @@ -0,0 +1,21 @@ +From 7e49721ad0efdec3a81e20bc58e385ea5d2b87b7 Mon Sep 17 00:00:00 2001 +From: Shawn O. Pearce <sop@xxxxxxxxxx> +Date: Fri, 12 Dec 2008 12:45:17 -0800 +Subject: [PATCH] make zero have a 3 + +--- + zero.bin | Bin 4096 -> 4096 bytes + 1 files changed, 0 insertions(+), 0 deletions(-) + +diff --git a/zero.bin b/zero.bin +index 08e7df176454f3ee5eeda13efa0adaa54828dfd8..d70d8710b6d32ff844af0ee7c247e4b4b051867f 100644 +GIT binary patch +delta 12 +TcmZorXi%6C%4ociaTPxR8IA+R + +delta 11 +ScmZorXi(Uguz-JJK>`37u>@iO + +-- +1.6.1.rc2.306.ge5d5e + diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_GitBinary.patch b/org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_GitBinaryLiteral.patch similarity index 100% rename from org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_GitBinary.patch rename to org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_GitBinaryLiteral.patch diff --git a/org.spearce.jgit/src/org/spearce/jgit/patch/BinaryHunk.java b/org.spearce.jgit/src/org/spearce/jgit/patch/BinaryHunk.java index 3e07ec4..92eab86 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/patch/BinaryHunk.java +++ b/org.spearce.jgit/src/org/spearce/jgit/patch/BinaryHunk.java @@ -100,7 +100,7 @@ int parseHunk(int ptr, final int end) { } else if (match(buf, ptr, DELTA) >= 0) { type = Type.DELTA_DEFLATED; - length = parseBase10(buf, ptr + LITERAL.length, null); + length = parseBase10(buf, ptr + DELTA.length, null); } else { // Not a valid binary hunk. Signal to the caller that -- 1.6.1.rc2.306.ge5d5e -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html