Patch API bug fixes and diff --cc suport
cover Patch API bug fixes and diff --cc suport
This series addes new unit tests for the patch API, closing some gaps in our test coverage. Some of those tests identified bugs in the implementation, and those are now fixed.
The final patch in the series adds support for "diff -cc" patches, used to show an "evil merge" commit's conflict resolution.
Shawn O. Pearce (12):
Assert the HunkHeader.getFileHeader returns the right file Add tests to cover more methods of BinaryHunk
Add a simple toString to FormatError to facilitate debugging Allow FileHeader to create its HunkHeader children Refactor the old/pre-image data in HunkHeader to support >1 ancestor Assert the ChunkHeader.OldImage.getId uses FileHeader.getOldImage Allow a stray LF at the end of a hunk
Fix HunkHeader start line when parsing "@@ -1 +1 @@" style headers Add test cases for parsing "\ No newline at end of file" style
patches
Use FileMode.MISSING when a file is added or deleted rather than null Add a test for delta binary patch parsing and fix a bug in it Add support for parsing "diff --cc" style patches
.../spearce/jgit/patch/EGitPatchHistoryTest.java | 4 +-
.../tst/org/spearce/jgit/patch/FileHeaderTest.java | 4 +-
.../org/spearce/jgit/patch/PatchCcErrorTest.java | 97 +++++++++
.../tst/org/spearce/jgit/patch/PatchCcTest.java | 200 ++++++++++++++++++
.../tst/org/spearce/jgit/patch/PatchTest.java | 165 +++++++++++++--
.../jgit/patch/testError_CcTruncatedOld.patch | 24 +++
.../jgit/patch/testParse_AddNoNewline.patch | 20 ++
.../jgit/patch/testParse_CcDeleteFile.patch | 12 +
.../spearce/jgit/patch/testParse_CcNewFile.patch | 14 ++
.../jgit/patch/testParse_FixNoNewline.patch | 20 ++
.../jgit/patch/testParse_GitBinaryDelta.patch | 21 ++
...nary.patch => testParse_GitBinaryLiteral.patch} | 0
.../spearce/jgit/patch/testParse_OneFileCc.patch | 27 +++
.../src/org/spearce/jgit/patch/BinaryHunk.java | 2 +-
.../org/spearce/jgit/patch/CombinedFileHeader.java | 213 ++++++++++++++++++++
.../org/spearce/jgit/patch/CombinedHunkHeader.java | 191 ++++++++++++++++++
.../src/org/spearce/jgit/patch/FileHeader.java | 64 ++++--
.../src/org/spearce/jgit/patch/FormatError.java | 14 ++
.../src/org/spearce/jgit/patch/HunkHeader.java | 134 +++++++-----
.../src/org/spearce/jgit/patch/Patch.java | 24 ++-
20 files changed, 1134 insertions(+), 116 deletions(-)
create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchCcErrorTest.java
create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchCcTest.java
create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/patch/testError_CcTruncatedOld.patch
create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_AddNoNewline.patch
create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_CcDeleteFile.patch
create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_CcNewFile.patch
create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_FixNoNewline.patch
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%)
create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_OneFileCc.patch
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/patch/CombinedFileHeader.java
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/patch/CombinedHunkHeader.javaPATCH 1/12 Assert the HunkHeader.getFileHeader returns the right file
--- .../tst/org/spearce/jgit/patch/PatchTest.java | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchTest.java +2 -0
@@ -80,6 +80,7 @@ assertSame(FileHeader.PatchType.UNIFIED, fRepositoryConfigTest assertEquals(1, fRepositoryConfigTest.getHunks().size()); { final HunkHeader h = fRepositoryConfigTest.getHunks().get(0); + assertSame(fRepositoryConfigTest, h.getFileHeader()); assertEquals(921, h.startOffset); assertEquals(109, h.getOldStartLine()); assertEquals(4, h.getOldLineCount());
@@ -102,6 +103,7 @@ assertSame(FileHeader.PatchType.UNIFIED, fRepositoryConfig assertEquals(3, fRepositoryConfig.getHunks().size()); { final HunkHeader h = fRepositoryConfig.getHunks().get(0); + assertSame(fRepositoryConfig, h.getFileHeader()); assertEquals(1803, h.startOffset); assertEquals(236, h.getOldStartLine()); assertEquals(9, h.getOldLineCount());
Signature · 1 line
1.6.1.rc2.306.ge5d5e
PATCH 2/12 Add tests to cover more methods of BinaryHunk
--- .../tst/org/spearce/jgit/patch/PatchTest.java | 16 ++++++++++++---- 1 files changed, 12 insertions(+), 4 deletions(-)
org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchTest.java +12 -4
@@ -199,10 +199,18 @@ assertTrue(fh.getNewName().startsWith( assertTrue(fh.getHunks().isEmpty()); assertTrue(fh.hasMetaDataChanges()); - assertNotNull(fh.getForwardBinaryHunk()); - assertNotNull(fh.getReverseBinaryHunk()); - assertEquals(binsizes[i], fh.getForwardBinaryHunk().getSize()); - assertEquals(0, fh.getReverseBinaryHunk().getSize()); + final BinaryHunk fwd = fh.getForwardBinaryHunk(); + final BinaryHunk rev = fh.getReverseBinaryHunk(); + assertNotNull(fwd); + assertNotNull(rev); + assertEquals(binsizes[i], fwd.getSize()); + assertEquals(0, rev.getSize()); + + assertSame(fh, fwd.getFileHeader()); + assertSame(fh, rev.getFileHeader()); + + assertSame(BinaryHunk.Type.LITERAL_DEFLATED, fwd.getType()); + assertSame(BinaryHunk.Type.LITERAL_DEFLATED, rev.getType()); } final FileHeader fh = p.getFiles().get(4);
Signature · 1 line
1.6.1.rc2.306.ge5d5e
PATCH 3/12 Add a simple toString to FormatError to facilitate debugging
--- .../src/org/spearce/jgit/patch/FormatError.java | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-)
org.spearce.jgit/src/org/spearce/jgit/patch/FormatError.java +14 -0
@@ -92,4 +92,18 @@ public String getLineText() { final int eol = RawParseUtils.nextLF(buf, offset); return RawParseUtils.decode(Constants.CHARSET, buf, offset, eol); } + + @Override + public String toString() { + final StringBuilder r = new StringBuilder(); + r.append(getSeverity().name().toLowerCase()); + r.append(": at offset "); + r.append(getOffset()); + r.append(": "); + r.append(getMessage()); + r.append("\n"); + r.append(" in "); + r.append(getLineText()); + return r.toString(); + } }
Signature · 1 line
1.6.1.rc2.306.ge5d5e
PATCH 4/12 Allow FileHeader to create its HunkHeader children
By using a factory method on FileHeader we can later subclass the FileHeader class to handle "diff --cc" style patches, and let it create its own subclass of HunkHeader to handle the specialized form of the n-way diff.
The getParentCount() method is hard-coded to return 1 in the 2-way diff case as there is exactly one parent. But in a "diff --cc" we need to verify the hunk header has the same number of parents as the file header in order to parse the hunk. So a subclass of the FileHeader would need to override getParentCount() to return the actual number of '@' symbols (less 1) that should appear in each hunk header line. (E.g. a 3-way diff shows "@@@ -" so the parent count should be 2.)
--- .../src/org/spearce/jgit/patch/FileHeader.java | 8 ++++++++ .../src/org/spearce/jgit/patch/Patch.java | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-)
org.spearce.jgit/src/org/spearce/jgit/patch/FileHeader.java +8 -0
@@ -169,6 +169,10 @@ FileHeader(final byte[] b, final int offset) { patchType = PatchType.UNIFIED; } + int getParentCount() { + return 1; + } + /** * Get the old name associated with this file. * <p>
@@ -274,6 +278,10 @@ void addHunk(final HunkHeader h) { hunks.add(h); } + HunkHeader newHunkHeader(final int offset) { + return new HunkHeader(this, offset); + } + /** @return if a {@link PatchType#GIT_BINARY}, the new-image delta/literal */ public BinaryHunk getForwardBinaryHunk() { return forwardBinaryHunk;
org.spearce.jgit/src/org/spearce/jgit/patch/Patch.java +2 -2
@@ -281,8 +281,8 @@ private int parseHunks(final FileHeader fh, int c, final int end) { if (match(buf, c, NEW_NAME) >= 0) break; - if (isHunkHdr(buf, c, end) == 1) { - final HunkHeader h = new HunkHeader(fh, c); + if (isHunkHdr(buf, c, end) == fh.getParentCount()) { + final HunkHeader h = fh.newHunkHeader(c); h.parseHeader(end); c = h.parseBody(this, end); h.endOffset = c;
Signature · 1 line
1.6.1.rc2.306.ge5d5e
PATCH 5/12 Refactor the old/pre-image data in HunkHeader to support >1 ancestor
The "diff --cc" format uses more than one ancestor in each hunk, so we need to expand the hunk header information in a way that allows access to the data for each ancestor. This change moves the information relative to the old/pre-image ancestor in a 2-way patch into an OldImage object. In a 2-way patch we only have one OldImage, but in a "diff --cc" patch we will have more than one of these available in each hunk.
--- .../spearce/jgit/patch/EGitPatchHistoryTest.java | 4 +- .../tst/org/spearce/jgit/patch/PatchTest.java | 36 +++--- .../src/org/spearce/jgit/patch/HunkHeader.java | 124 ++++++++++++-------- 3 files changed, 95 insertions(+), 69 deletions(-)
org.spearce.jgit.test/exttst/org/spearce/jgit/patch/EGitPatchHistoryTest.java +2 -2
@@ -110,8 +110,8 @@ void onCommit(String cid, byte[] buf) { assertNotNull("No " + nid, s); int added = 0, deleted = 0; for (final HunkHeader h : fh.getHunks()) { - added += h.getLinesAdded(); - deleted += h.getLinesDeleted(); + added += h.getOldImage().getLinesAdded(); + deleted += h.getOldImage().getLinesDeleted(); } if (s.added == added) {
org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchTest.java +18 -18
@@ -82,14 +82,14 @@ assertSame(FileHeader.PatchType.UNIFIED, fRepositoryConfigTest final HunkHeader h = fRepositoryConfigTest.getHunks().get(0); assertSame(fRepositoryConfigTest, h.getFileHeader()); assertEquals(921, h.startOffset); - assertEquals(109, h.getOldStartLine()); - assertEquals(4, h.getOldLineCount()); + assertEquals(109, h.getOldImage().getStartLine()); + assertEquals(4, h.getOldImage().getLineCount()); assertEquals(109, h.getNewStartLine()); assertEquals(11, h.getNewLineCount()); assertEquals(4, h.getLinesContext()); - assertEquals(7, h.getLinesAdded()); - assertEquals(0, h.getLinesDeleted()); + assertEquals(7, h.getOldImage().getLinesAdded()); + assertEquals(0, h.getOldImage().getLinesDeleted()); assertEquals(1490, h.endOffset); }
@@ -105,42 +105,42 @@ assertSame(FileHeader.PatchType.UNIFIED, fRepositoryConfig final HunkHeader h = fRepositoryConfig.getHunks().get(0); assertSame(fRepositoryConfig, h.getFileHeader()); assertEquals(1803, h.startOffset); - assertEquals(236, h.getOldStartLine()); - assertEquals(9, h.getOldLineCount()); + assertEquals(236, h.getOldImage().getStartLine()); + assertEquals(9, h.getOldImage().getLineCount()); assertEquals(236, h.getNewStartLine()); assertEquals(9, h.getNewLineCount()); assertEquals(7, h.getLinesContext()); - assertEquals(2, h.getLinesAdded()); - assertEquals(2, h.getLinesDeleted()); + assertEquals(2, h.getOldImage().getLinesAdded()); + assertEquals(2, h.getOldImage().getLinesDeleted()); assertEquals(2434, h.endOffset); } { final HunkHeader h = fRepositoryConfig.getHunks().get(1); assertEquals(2434, h.startOffset); - assertEquals(300, h.getOldStartLine()); - assertEquals(7, h.getOldLineCount()); + assertEquals(300, h.getOldImage().getStartLine()); + assertEquals(7, h.getOldImage().getLineCount()); assertEquals(300, h.getNewStartLine()); assertEquals(7, h.getNewLineCount()); assertEquals(6, h.getLinesContext()); - assertEquals(1, h.getLinesAdded()); - assertEquals(1, h.getLinesDeleted()); + assertEquals(1, h.getOldImage().getLinesAdded()); + assertEquals(1, h.getOldImage().getLinesDeleted()); assertEquals(2816, h.endOffset); } { final HunkHeader h = fRepositoryConfig.getHunks().get(2); assertEquals(2816, h.startOffset); - assertEquals(954, h.getOldStartLine()); - assertEquals(7, h.getOldLineCount()); + assertEquals(954, h.getOldImage().getStartLine()); + assertEquals(7, h.getOldImage().getLineCount()); assertEquals(954, h.getNewStartLine()); assertEquals(7, h.getNewLineCount()); assertEquals(6, h.getLinesContext()); - assertEquals(1, h.getLinesAdded()); - assertEquals(1, h.getLinesDeleted()); + assertEquals(1, h.getOldImage().getLinesAdded()); + assertEquals(1, h.getOldImage().getLinesDeleted()); assertEquals(3035, h.endOffset); }
@@ -177,7 +177,7 @@ assertTrue(fh.getNewName().startsWith( assertNull(fh.getForwardBinaryHunk()); assertNull(fh.getReverseBinaryHunk()); assertEquals(1, fh.getHunks().size()); - assertEquals(272, fh.getHunks().get(0).getOldStartLine()); + assertEquals(272, fh.getHunks().get(0).getOldImage().getStartLine()); } public void testParse_GitBinary() throws IOException {
@@ -222,7 +222,7 @@ assertTrue(fh.getNewName().startsWith( assertNull(fh.getForwardBinaryHunk()); assertNull(fh.getReverseBinaryHunk()); assertEquals(1, fh.getHunks().size()); - assertEquals(272, fh.getHunks().get(0).getOldStartLine()); + assertEquals(272, fh.getHunks().get(0).getOldImage().getStartLine()); } private Patch parseTestPatchFile() throws IOException {
org.spearce.jgit/src/org/spearce/jgit/patch/HunkHeader.java +75 -49
205 lines not on this page · raw message
Signature · 1 line
1.6.1.rc2.306.ge5d5e
PATCH 6/12 Assert the ChunkHeader.OldImage.getId uses FileHeader.getOldImage
These should always produce the same AbbreviatedObjectId.
--- .../tst/org/spearce/jgit/patch/PatchTest.java | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchTest.java +3 -0
@@ -90,6 +90,8 @@ assertSame(FileHeader.PatchType.UNIFIED, fRepositoryConfigTest assertEquals(4, h.getLinesContext()); assertEquals(7, h.getOldImage().getLinesAdded()); assertEquals(0, h.getOldImage().getLinesDeleted()); + assertSame(fRepositoryConfigTest.getOldId(), h.getOldImage() + .getId()); assertEquals(1490, h.endOffset); }
@@ -113,6 +115,7 @@ assertSame(FileHeader.PatchType.UNIFIED, fRepositoryConfig assertEquals(7, h.getLinesContext()); assertEquals(2, h.getOldImage().getLinesAdded()); assertEquals(2, h.getOldImage().getLinesDeleted()); + assertSame(fRepositoryConfig.getOldId(), h.getOldImage().getId()); assertEquals(2434, h.endOffset); }
Signature · 1 line
1.6.1.rc2.306.ge5d5e
PATCH 7/12 Allow a stray LF at the end of a hunk
If a hunk ends and is followed by a stray LF its not worth creating a warning for. A single extra blank line isn't all that interesting relative to the other sorts of data we might find at the end of a patch hunk.
--- .../src/org/spearce/jgit/patch/Patch.java | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-)
org.spearce.jgit/src/org/spearce/jgit/patch/Patch.java +10 -3
@@ -287,9 +287,16 @@ private int parseHunks(final FileHeader fh, int c, final int end) { c = h.parseBody(this, end); h.endOffset = c; fh.addHunk(h); - if (c < end && buf[c] != '@' && buf[c] != 'd' - && match(buf, c, SIG_FOOTER) < 0) { - warn(buf, c, "Unexpected hunk trailer"); + if (c < end) { + switch (buf[c]) { + case '@': + case 'd': + case '\n': + break; + default: + if (match(buf, c, SIG_FOOTER) < 0) + warn(buf, c, "Unexpected hunk trailer"); + } } continue; }
Signature · 1 line
1.6.1.rc2.306.ge5d5e
PATCH 8/12 Fix HunkHeader start line when parsing "@@ -1 +1 @@" style headers
In this case we are listing a delta of 1 line but also the position start is line 1.
--- .../src/org/spearce/jgit/patch/HunkHeader.java | 12 ++++-------- 1 files changed, 4 insertions(+), 8 deletions(-)
org.spearce.jgit/src/org/spearce/jgit/patch/HunkHeader.java +4 -8
@@ -152,18 +152,14 @@ void parseHeader(final int end) { old.startLine = -parseBase10(buf, ptr.value, ptr); if (buf[ptr.value] == ',') old.lineCount = parseBase10(buf, ptr.value + 1, ptr); - else { - old.lineCount = old.startLine; - old.startLine = 0; - } + else + old.lineCount = 1; newStartLine = parseBase10(buf, ptr.value + 1, ptr); if (buf[ptr.value] == ',') newLineCount = parseBase10(buf, ptr.value + 1, ptr); - else { - newLineCount = newStartLine; - newStartLine = 0; - } + else + newLineCount = 1; } int parseBody(final Patch script, final int end) {
Signature · 1 line
1.6.1.rc2.306.ge5d5e
PATCH 9/12 Add test cases for parsing "\ No newline at end of file" style patches
--- .../tst/org/spearce/jgit/patch/PatchTest.java | 68 ++++++++++++++++++++ .../jgit/patch/testParse_AddNoNewline.patch | 20 ++++++ .../jgit/patch/testParse_FixNoNewline.patch | 20 ++++++ 3 files changed, 108 insertions(+), 0 deletions(-) create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_AddNoNewline.patch create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_FixNoNewline.patch
org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchTest.java +68 -0
@@ -228,6 +228,74 @@ assertTrue(fh.getNewName().startsWith( assertEquals(272, fh.getHunks().get(0).getOldImage().getStartLine()); } + public void testParse_FixNoNewline() throws IOException { + final Patch p = parseTestPatchFile(); + assertEquals(1, p.getFiles().size()); + assertTrue(p.getErrors().isEmpty()); + + final FileHeader f = p.getFiles().get(0); + + assertEquals("a", f.getNewName()); + assertEquals(252, f.startOffset); + + assertEquals("2e65efe", f.getOldId().name()); + assertEquals("f2ad6c7", f.getNewId().name()); + assertSame(FileHeader.PatchType.UNIFIED, f.getPatchType()); + assertSame(FileMode.REGULAR_FILE, f.getOldMode()); + assertSame(FileMode.REGULAR_FILE, f.getNewMode()); + assertEquals(1, f.getHunks().size()); + { + final HunkHeader h = f.getHunks().get(0); + assertSame(f, h.getFileHeader()); + assertEquals(317, h.startOffset); + assertEquals(1, h.getOldImage().getStartLine()); + assertEquals(1, h.getOldImage().getLineCount()); + assertEquals(1, h.getNewStartLine()); + assertEquals(1, h.getNewLineCount()); + + assertEquals(0, h.getLinesContext()); + assertEquals(1, h.getOldImage().getLinesAdded()); + assertEquals(1, h.getOldImage().getLinesDeleted()); + assertSame(f.getOldId(), h.getOldImage().getId()); + + assertEquals(363, h.endOffset); + } + } + + public void testParse_AddNoNewline() throws IOException { + final Patch p = parseTestPatchFile(); + assertEquals(1, p.getFiles().size()); + assertTrue(p.getErrors().isEmpty()); + + final FileHeader f = p.getFiles().get(0); + + assertEquals("a", f.getNewName()); + assertEquals(256, f.startOffset); + + assertEquals("f2ad6c7", f.getOldId().name()); + assertEquals("c59d9b6", f.getNewId().name()); + assertSame(FileHeader.PatchType.UNIFIED, f.getPatchType()); + assertSame(FileMode.REGULAR_FILE, f.getOldMode()); + assertSame(FileMode.REGULAR_FILE, f.getNewMode()); + assertEquals(1, f.getHunks().size()); + { + final HunkHeader h = f.getHunks().get(0); + assertSame(f, h.getFileHeader()); + assertEquals(321, h.startOffset); + assertEquals(1, h.getOldImage().getStartLine()); + assertEquals(1, h.getOldImage().getLineCount()); + assertEquals(1, h.getNewStartLine()); + assertEquals(1, h.getNewLineCount()); + + assertEquals(0, h.getLinesContext()); + assertEquals(1, h.getOldImage().getLinesAdded()); + assertEquals(1, h.getOldImage().getLinesDeleted()); + assertSame(f.getOldId(), h.getOldImage().getId()); + + assertEquals(367, h.endOffset); + } + } + private Patch parseTestPatchFile() throws IOException { final String patchFile = getName() + ".patch"; final InputStream in = getClass().getResourceAsStream(patchFile);
org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_AddNoNewline.patch new file +20 -0
@@ -0,0 +1,20 @@ +From ca4719a4b2d93a469f61d1ddfb3e39ecbabfcd69 Mon Sep 17 00:00:00 2001 +From: Shawn O. Pearce <[email protected]> +Date: Fri, 12 Dec 2008 12:35:14 -0800 +Subject: [PATCH] introduce no lf again + +--- + a | 2 +- + 1 files changed, 1 insertions(+), 1 deletions(-) + +diff --git a/a b/a +index f2ad6c7..c59d9b6 100644 +--- a/a ++++ b/a +@@ -1 +1 @@ +-c ++d +\ No newline at end of file +-- +1.6.1.rc2.306.ge5d5e +
org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_FixNoNewline.patch new file +20 -0
@@ -0,0 +1,20 @@ +From 1beb3ec1fe68ff18b0287396096442e12c34787a Mon Sep 17 00:00:00 2001 +From: Shawn O. Pearce <[email protected]> +Date: Fri, 12 Dec 2008 12:29:45 -0800 +Subject: [PATCH] make c and add lf + +--- + a | 2 +- + 1 files changed, 1 insertions(+), 1 deletions(-) + +diff --git a/a b/a +index 2e65efe..f2ad6c7 100644 +--- a/a ++++ b/a +@@ -1 +1 @@ +-a +\ No newline at end of file ++c +-- +1.6.1.rc2.306.ge5d5e +
Signature · 1 line
1.6.1.rc2.306.ge5d5e
PATCH 10/12 Use FileMode.MISSING when a file is added or deleted rather than null
Null is better used to indicate "no mode information at all" in the patch, while FileMode.MISSING is already commonly used within the TreeWalk code to mean "this path doesn't exist in this tree". In the context of a patch to create or delete a file, MISSING makes a lot more sense for the application to work with.
--- .../tst/org/spearce/jgit/patch/FileHeaderTest.java | 4 ++-- .../tst/org/spearce/jgit/patch/PatchTest.java | 1 + .../src/org/spearce/jgit/patch/FileHeader.java | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-)
org.spearce.jgit.test/tst/org/spearce/jgit/patch/FileHeaderTest.java +2 -2
@@ -153,7 +153,7 @@ public void testParseUnicodeName_NewFile() { assertSame(FileHeader.PatchType.UNIFIED, fh.getPatchType()); assertTrue(fh.hasMetaDataChanges()); - assertNull(fh.getOldMode()); + assertSame(FileMode.MISSING, fh.getOldMode()); assertSame(FileMode.REGULAR_FILE, fh.getNewMode()); assertEquals("0000000", fh.getOldId().name());
@@ -179,7 +179,7 @@ public void testParseUnicodeName_DeleteFile() { assertTrue(fh.hasMetaDataChanges()); assertSame(FileMode.REGULAR_FILE, fh.getOldMode()); - assertNull(fh.getNewMode()); + assertSame(FileMode.MISSING, fh.getNewMode()); assertEquals("7898192", fh.getOldId().name()); assertEquals("0000000", fh.getNewId().name());
org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchTest.java +1 -0
@@ -160,6 +160,7 @@ public void testParse_NoBinary() throws IOException { assertNotNull(fh.getOldId()); assertNotNull(fh.getNewId()); assertEquals("0000000", fh.getOldId().name()); + assertSame(FileMode.MISSING, fh.getOldMode()); assertSame(FileMode.REGULAR_FILE, fh.getNewMode()); assertTrue(fh.getNewName().startsWith( "org.spearce.egit.ui/icons/toolbar/"));
org.spearce.jgit/src/org/spearce/jgit/patch/FileHeader.java +2 -0
@@ -386,9 +386,11 @@ int parseGitHeaders(int ptr, final int end) { } else if (match(buf, ptr, DELETED_FILE_MODE) >= 0) { oldMode = parseFileMode(ptr + DELETED_FILE_MODE.length, eol); + newMode = FileMode.MISSING; changeType = ChangeType.DELETE; } else if (match(buf, ptr, NEW_FILE_MODE) >= 0) { + oldMode = FileMode.MISSING; newMode = parseFileMode(ptr + NEW_FILE_MODE.length, eol); changeType = ChangeType.ADD;
Signature · 1 line
1.6.1.rc2.306.ge5d5e
PATCH 11/12 Add a test for delta binary patch parsing and fix a bug in it
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.
---
.../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%)org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchTest.java +38 -1
@@ -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());
org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_GitBinaryDelta.patch new file +21 -0
@@ -0,0 +1,21 @@ +From 7e49721ad0efdec3a81e20bc58e385ea5d2b87b7 Mon Sep 17 00:00:00 2001 +From: Shawn O. Pearce <[email protected]> +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 +
org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_GitBinaryLiteral.patch renamed from org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_GitBinary.patch +0 -0
org.spearce.jgit/src/org/spearce/jgit/patch/BinaryHunk.java +1 -1
@@ -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
Signature · 1 line
1.6.1.rc2.306.ge5d5e
PATCH 12/12 Add support for parsing "diff --cc" style patches
Even though the diff --cc format used by Git is only meant to be read by humans, JGit needs to be able to parse these to get the patch metadata so it can be shown in a user interface to facilitate code review processes.
Patches are parsed into the specialized CombinedFileHeader and CombinedHunkHeader classes, where the old image information is augmented with additional fields for the arbitrary number of parents that can appear in such patches. These cost more in terms of memory, but "diff --cc" style patches tend to occur very infrequently as they only occur during a merge conflict resolution.
--- .../org/spearce/jgit/patch/PatchCcErrorTest.java | 97 +++++++++ .../tst/org/spearce/jgit/patch/PatchCcTest.java | 200 ++++++++++++++++++ .../jgit/patch/testError_CcTruncatedOld.patch | 24 +++ .../jgit/patch/testParse_CcDeleteFile.patch | 12 + .../spearce/jgit/patch/testParse_CcNewFile.patch | 14 ++ .../spearce/jgit/patch/testParse_OneFileCc.patch | 27 +++ .../org/spearce/jgit/patch/CombinedFileHeader.java | 213 ++++++++++++++++++++ .../org/spearce/jgit/patch/CombinedHunkHeader.java | 191 ++++++++++++++++++ .../src/org/spearce/jgit/patch/FileHeader.java | 56 +++--- .../src/org/spearce/jgit/patch/HunkHeader.java | 2 +- .../src/org/spearce/jgit/patch/Patch.java | 7 +- 11 files changed, 814 insertions(+), 29 deletions(-) create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchCcErrorTest.java create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchCcTest.java create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/patch/testError_CcTruncatedOld.patch create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_CcDeleteFile.patch create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_CcNewFile.patch create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_OneFileCc.patch create mode 100644 org.spearce.jgit/src/org/spearce/jgit/patch/CombinedFileHeader.java create mode 100644 org.spearce.jgit/src/org/spearce/jgit/patch/CombinedHunkHeader.java
org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchCcErrorTest.java new file +97 -0
@@ -0,0 +1,97 @@ +/* + * Copyright (C) 2008, Google Inc. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * - Neither the name of the Git Development Community nor the + * names of its contributors may be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.spearce.jgit.patch; + +import java.io.IOException; +import java.io.InputStream; + +import junit.framework.TestCase; + +public class PatchCcErrorTest extends TestCase { + public void testError_CcTruncatedOld() throws IOException { + final Patch p = parseTestPatchFile(); + assertEquals(1, p.getFiles().size()); + assertEquals(3, p.getErrors().size()); + { + final FormatError e = p.getErrors().get(0); + assertSame(FormatError.Severity.ERROR, e.getSeverity()); + assertEquals( + "Truncated hunk, at least 1 lines is missing for ancestor 1", + e.getMessage()); + assertEquals(346, e.getOffset()); + assertTrue(e.getLineText().startsWith( + "@@@ -55,12 -163,13 +163,15 @@@ public ")); + } + { + final FormatError e = p.getErrors().get(1); + assertSame(FormatError.Severity.ERROR, e.getSeverity()); + assertEquals( + "Truncated hunk, at least 2 lines is missing for ancestor 2", + e.getMessage()); + assertEquals(346, e.getOffset()); + assertTrue(e.getLineText().startsWith( + "@@@ -55,12 -163,13 +163,15 @@@ public ")); + } + { + final FormatError e = p.getErrors().get(2); + assertSame(FormatError.Severity.ERROR, e.getSeverity()); + assertEquals("Truncated hunk, at least 3 new lines is missing", e + .getMessage()); + assertEquals(346, e.getOffset()); + assertTrue(e.getLineText().startsWith( + "@@@ -55,12 -163,13 +163,15 @@@ public ")); + } + } + + private Patch parseTestPatchFile() throws IOException { + final String patchFile = getName() + ".patch"; + final InputStream in = getClass().getResourceAsStream(patchFile); + if (in == null) { + fail("No " + patchFile + " test vector"); + return null; // Never happens + } + try { + final Patch p = new Patch(); + p.parse(in); + return p; + } finally { + in.close(); + } + } + +}
org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchCcTest.java new file +200 -0
200 lines not on this page · raw message
org.spearce.jgit.test/tst/org/spearce/jgit/patch/testError_CcTruncatedOld.patch new file +24 -0
@@ -0,0 +1,24 @@ +commit 1a56639bbea8e8cbfbe5da87746de97f9217ce9b +Date: Tue May 13 00:43:56 2008 +0200 + ... + +diff --cc org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java +index 169356b,dd8c317..fd85931 +mode 100644,100644..100755 +--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java ++++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java +@@@ -55,12 -163,13 +163,15 @@@ public class UIText extends NLS + + /** */ + public static String ResourceHistory_toggleCommentWrap; ++ + /** */ + + /** */ + public static String ResourceHistory_toggleRevDetail; + /** */ + public static String ResourceHistory_toggleRevComment; + /** */ + public static String ResourceHistory_toggleTooltips; + + +commit 1a56639bbea8e8cbfbe5da87746de97f9217ce9b
org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_CcDeleteFile.patch new file +12 -0
@@ -0,0 +1,12 @@ +commit 740709ece2412856c0c3eabd4dc4a4cf115b0de6 +Merge: 5c19b43... 13a2c0d... +Author: Shawn O. Pearce <[email protected]> +Date: Fri Dec 12 13:26:52 2008 -0800 + + Merge branch 'b' into d + +diff --cc a +index 7898192,2e65efe..0000000 +deleted file mode 100644,100644 +--- a/a ++++ /dev/null
org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_CcNewFile.patch new file +14 -0
@@ -0,0 +1,14 @@ +commit 6cb8160a4717d51fd3cc0baf721946daa60cf921 +Merge: 5c19b43... 13a2c0d... +Author: Shawn O. Pearce <[email protected]> +Date: Fri Dec 12 13:26:52 2008 -0800 + + Merge branch 'b' into d + +diff --cc d +index 0000000,0000000..4bcfe98 +new file mode 100644 +--- /dev/null ++++ b/d +@@@ -1,0 -1,0 +1,1 @@@ +++d
org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_OneFileCc.patch new file +27 -0
@@ -0,0 +1,27 @@ +commit 1a56639bbea8e8cbfbe5da87746de97f9217ce9b +Date: Tue May 13 00:43:56 2008 +0200 + ... + +diff --cc org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java +index 169356b,dd8c317..fd85931 +mode 100644,100644..100755 +--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java ++++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java +@@@ -55,12 -163,13 +163,15 @@@ public class UIText extends NLS + + /** */ + public static String ResourceHistory_toggleCommentWrap; ++ + /** */ + + public static String ResourceHistory_toggleCommentFill; + + /** */ + public static String ResourceHistory_toggleRevDetail; ++ + /** */ + public static String ResourceHistory_toggleRevComment; ++ + /** */ + public static String ResourceHistory_toggleTooltips; + + +commit 1a56639bbea8e8cbfbe5da87746de97f9217ce9b
org.spearce.jgit/src/org/spearce/jgit/patch/CombinedFileHeader.java new file +213 -0
213 lines not on this page · raw message
org.spearce.jgit/src/org/spearce/jgit/patch/CombinedHunkHeader.java new file +191 -0
191 lines not on this page · raw message
org.spearce.jgit/src/org/spearce/jgit/patch/FileHeader.java +32 -24
129 lines not on this page · raw message
org.spearce.jgit/src/org/spearce/jgit/patch/HunkHeader.java +1 -1
@@ -84,7 +84,7 @@ public int getLinesAdded() { public abstract AbbreviatedObjectId getId(); } - private final FileHeader file; + final FileHeader file; /** Offset within {@link #file}.buf to the "@@ -" line. */ final int startOffset;
org.spearce.jgit/src/org/spearce/jgit/patch/Patch.java +3 -4
@@ -94,7 +94,7 @@ public void addFile(final FileHeader fh) { } /** @return list of files described in the patch, in occurrence order. */ - public List<FileHeader> getFiles() { + public List<? extends FileHeader> getFiles() { return files; }
@@ -238,9 +238,8 @@ private int parseDiffCombined(final byte[] hdr, final byte[] buf, if (ptr < 0) return skipFile(buf, start, end); - // TODO Support parsing diff --cc headers - // TODO parse diff --cc hunks - warn(buf, start, "diff --cc format not supported"); + ptr = fh.parseGitHeaders(ptr, end); + ptr = parseHunks(fh, ptr, end); fh.endOffset = ptr; addFile(fh); return ptr;
Signature · 1 line
1.6.1.rc2.306.ge5d5e
PATCH v2 12/12 Add support for parsing "diff --cc" style patches
Even though the diff --cc format used by Git is only meant to be read by humans, JGit needs to be able to parse these to get the patch metadata so it can be shown in a user interface to facilitate code review processes.
Patches are parsed into the specialized CombinedFileHeader and CombinedHunkHeader classes, where the old image information is augmented with additional fields for the arbitrary number of parents that can appear in such patches. These cost more in terms of memory, but "diff --cc" style patches tend to occur very infrequently as they only occur during a merge conflict resolution.
---
v2 is necessary because of the CombinedFileHeader glitch in an earlier series.
.../org/spearce/jgit/patch/PatchCcErrorTest.java | 97 +++++++++ .../tst/org/spearce/jgit/patch/PatchCcTest.java | 200 ++++++++++++++++++ .../jgit/patch/testError_CcTruncatedOld.patch | 24 +++ .../jgit/patch/testParse_CcDeleteFile.patch | 12 + .../spearce/jgit/patch/testParse_CcNewFile.patch | 14 ++ .../spearce/jgit/patch/testParse_OneFileCc.patch | 27 +++ .../org/spearce/jgit/patch/CombinedFileHeader.java | 213 ++++++++++++++++++++ .../org/spearce/jgit/patch/CombinedHunkHeader.java | 191 ++++++++++++++++++ .../src/org/spearce/jgit/patch/FileHeader.java | 56 +++--- .../src/org/spearce/jgit/patch/HunkHeader.java | 2 +- .../src/org/spearce/jgit/patch/Patch.java | 9 +- 11 files changed, 815 insertions(+), 30 deletions(-) create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchCcErrorTest.java create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchCcTest.java create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/patch/testError_CcTruncatedOld.patch create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_CcDeleteFile.patch create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_CcNewFile.patch create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_OneFileCc.patch create mode 100644 org.spearce.jgit/src/org/spearce/jgit/patch/CombinedFileHeader.java create mode 100644 org.spearce.jgit/src/org/spearce/jgit/patch/CombinedHunkHeader.java
org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchCcErrorTest.java new file +97 -0
@@ -0,0 +1,97 @@ +/* + * Copyright (C) 2008, Google Inc. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * - Neither the name of the Git Development Community nor the + * names of its contributors may be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.spearce.jgit.patch; + +import java.io.IOException; +import java.io.InputStream; + +import junit.framework.TestCase; + +public class PatchCcErrorTest extends TestCase { + public void testError_CcTruncatedOld() throws IOException { + final Patch p = parseTestPatchFile(); + assertEquals(1, p.getFiles().size()); + assertEquals(3, p.getErrors().size()); + { + final FormatError e = p.getErrors().get(0); + assertSame(FormatError.Severity.ERROR, e.getSeverity()); + assertEquals( + "Truncated hunk, at least 1 lines is missing for ancestor 1", + e.getMessage()); + assertEquals(346, e.getOffset()); + assertTrue(e.getLineText().startsWith( + "@@@ -55,12 -163,13 +163,15 @@@ public ")); + } + { + final FormatError e = p.getErrors().get(1); + assertSame(FormatError.Severity.ERROR, e.getSeverity()); + assertEquals( + "Truncated hunk, at least 2 lines is missing for ancestor 2", + e.getMessage()); + assertEquals(346, e.getOffset()); + assertTrue(e.getLineText().startsWith( + "@@@ -55,12 -163,13 +163,15 @@@ public ")); + } + { + final FormatError e = p.getErrors().get(2); + assertSame(FormatError.Severity.ERROR, e.getSeverity()); + assertEquals("Truncated hunk, at least 3 new lines is missing", e + .getMessage()); + assertEquals(346, e.getOffset()); + assertTrue(e.getLineText().startsWith( + "@@@ -55,12 -163,13 +163,15 @@@ public ")); + } + } + + private Patch parseTestPatchFile() throws IOException { + final String patchFile = getName() + ".patch"; + final InputStream in = getClass().getResourceAsStream(patchFile); + if (in == null) { + fail("No " + patchFile + " test vector"); + return null; // Never happens + } + try { + final Patch p = new Patch(); + p.parse(in); + return p; + } finally { + in.close(); + } + } + +}
org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchCcTest.java new file +200 -0
200 lines not on this page · raw message
org.spearce.jgit.test/tst/org/spearce/jgit/patch/testError_CcTruncatedOld.patch new file +24 -0
@@ -0,0 +1,24 @@ +commit 1a56639bbea8e8cbfbe5da87746de97f9217ce9b +Date: Tue May 13 00:43:56 2008 +0200 + ... + +diff --cc org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java +index 169356b,dd8c317..fd85931 +mode 100644,100644..100755 +--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java ++++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java +@@@ -55,12 -163,13 +163,15 @@@ public class UIText extends NLS + + /** */ + public static String ResourceHistory_toggleCommentWrap; ++ + /** */ + + /** */ + public static String ResourceHistory_toggleRevDetail; + /** */ + public static String ResourceHistory_toggleRevComment; + /** */ + public static String ResourceHistory_toggleTooltips; + + +commit 1a56639bbea8e8cbfbe5da87746de97f9217ce9b
org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_CcDeleteFile.patch new file +12 -0
@@ -0,0 +1,12 @@ +commit 740709ece2412856c0c3eabd4dc4a4cf115b0de6 +Merge: 5c19b43... 13a2c0d... +Author: Shawn O. Pearce <[email protected]> +Date: Fri Dec 12 13:26:52 2008 -0800 + + Merge branch 'b' into d + +diff --cc a +index 7898192,2e65efe..0000000 +deleted file mode 100644,100644 +--- a/a ++++ /dev/null
org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_CcNewFile.patch new file +14 -0
@@ -0,0 +1,14 @@ +commit 6cb8160a4717d51fd3cc0baf721946daa60cf921 +Merge: 5c19b43... 13a2c0d... +Author: Shawn O. Pearce <[email protected]> +Date: Fri Dec 12 13:26:52 2008 -0800 + + Merge branch 'b' into d + +diff --cc d +index 0000000,0000000..4bcfe98 +new file mode 100644 +--- /dev/null ++++ b/d +@@@ -1,0 -1,0 +1,1 @@@ +++d
org.spearce.jgit.test/tst/org/spearce/jgit/patch/testParse_OneFileCc.patch new file +27 -0
@@ -0,0 +1,27 @@ +commit 1a56639bbea8e8cbfbe5da87746de97f9217ce9b +Date: Tue May 13 00:43:56 2008 +0200 + ... + +diff --cc org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java +index 169356b,dd8c317..fd85931 +mode 100644,100644..100755 +--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java ++++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java +@@@ -55,12 -163,13 +163,15 @@@ public class UIText extends NLS + + /** */ + public static String ResourceHistory_toggleCommentWrap; ++ + /** */ + + public static String ResourceHistory_toggleCommentFill; + + /** */ + public static String ResourceHistory_toggleRevDetail; ++ + /** */ + public static String ResourceHistory_toggleRevComment; ++ + /** */ + public static String ResourceHistory_toggleTooltips; + + +commit 1a56639bbea8e8cbfbe5da87746de97f9217ce9b
org.spearce.jgit/src/org/spearce/jgit/patch/CombinedFileHeader.java new file +213 -0
213 lines not on this page · raw message
org.spearce.jgit/src/org/spearce/jgit/patch/CombinedHunkHeader.java new file +191 -0
191 lines not on this page · raw message
org.spearce.jgit/src/org/spearce/jgit/patch/FileHeader.java +32 -24
129 lines not on this page · raw message
org.spearce.jgit/src/org/spearce/jgit/patch/HunkHeader.java +1 -1
@@ -84,7 +84,7 @@ public int getLinesAdded() { public abstract AbbreviatedObjectId getId(); } - private final FileHeader file; + final FileHeader file; /** Offset within {@link #file}.buf to the "@@ -" line. */ final int startOffset;
org.spearce.jgit/src/org/spearce/jgit/patch/Patch.java +4 -5
@@ -94,7 +94,7 @@ public void addFile(final FileHeader fh) { } /** @return list of files described in the patch, in occurrence order. */ - public List<FileHeader> getFiles() { + public List<? extends FileHeader> getFiles() { return files; }
@@ -233,14 +233,13 @@ private int parseDiffGit(final byte[] buf, final int start, final int end) { private int parseDiffCombined(final byte[] hdr, final byte[] buf, final int start, final int end) { - final FileHeader fh = new FileHeader(buf, start); + final CombinedFileHeader fh = new CombinedFileHeader(buf, start); int ptr = fh.parseGitFileName(start + hdr.length, end); if (ptr < 0) return skipFile(buf, start, end); - // TODO Support parsing diff --cc headers - // TODO parse diff --cc hunks - warn(buf, start, "diff --cc format not supported"); + ptr = fh.parseGitHeaders(ptr, end); + ptr = parseHunks(fh, ptr, end); fh.endOffset = ptr; addFile(fh); return ptr;
Signature · 1 line
1.6.1.rc2.306.ge5d5e