summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Aniszczyk <caniszczyk@gmail.com>2010-09-02 11:20:43 -0400
committerCode Review <codereview-daemon@eclipse.org>2010-09-02 11:20:43 -0400
commitdf0c9309c5518b173f5e836344515e9cf7b7fe5b (patch)
treeb78fd266d5a1eb5912e334cdaab6cafc49002fc4
parent2d71808ae06a5cfd91e0944c9ae2a3d1036019bd (diff)
parent797d5c4d4080c132ff2d5272ea4d6cffc9c903ba (diff)
downloadjgit-df0c9309c5518b173f5e836344515e9cf7b7fe5b.tar.gz
jgit-df0c9309c5518b173f5e836344515e9cf7b7fe5b.zip
Merge "Remove duplicated code in DiffFormatter"
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java56
1 files changed, 23 insertions, 33 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
index 231b8ab208..d8429a4cd8 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
@@ -212,33 +212,8 @@ public class DiffFormatter {
* be written to.
*/
public void format(DiffEntry ent) throws IOException {
- writeDiffHeader(out, ent);
-
- if (ent.getOldMode() == GITLINK || ent.getNewMode() == GITLINK) {
- writeGitLinkDiffText(out, ent);
- } else {
- if (db == null)
- throw new IllegalStateException(
- JGitText.get().repositoryIsRequired);
-
- ObjectReader reader = db.newObjectReader();
- byte[] aRaw, bRaw;
- try {
- aRaw = open(reader, ent.getOldMode(), ent.getOldId());
- bRaw = open(reader, ent.getNewMode(), ent.getNewId());
- } finally {
- reader.release();
- }
-
- if (RawText.isBinary(aRaw) || RawText.isBinary(bRaw)) {
- out.write(encodeASCII("Binary files differ\n"));
-
- } else {
- RawText a = rawTextFactory.create(aRaw);
- RawText b = rawTextFactory.create(bRaw);
- formatEdits(a, b, new MyersDiff(a, b).getEdits());
- }
- }
+ FormatResult res = createFormatResult(ent);
+ format(res.header, res.a, res.b);
}
private void writeGitLinkDiffText(OutputStream o, DiffEntry ent)
@@ -406,8 +381,8 @@ public class DiffFormatter {
if (!head.getHunks().isEmpty())
end = head.getHunks().get(0).getStartOffset();
out.write(head.getBuffer(), start, end - start);
-
- formatEdits(a, b, head.toEditList());
+ if (head.getPatchType() == PatchType.UNIFIED)
+ formatEdits(a, b, head.toEditList());
}
/**
@@ -603,6 +578,20 @@ public class DiffFormatter {
*/
public FileHeader createFileHeader(DiffEntry ent) throws IOException,
CorruptObjectException, MissingObjectException {
+ return createFormatResult(ent).header;
+ }
+
+ private static class FormatResult {
+ FileHeader header;
+
+ RawText a;
+
+ RawText b;
+ }
+
+ private FormatResult createFormatResult(DiffEntry ent) throws IOException,
+ CorruptObjectException, MissingObjectException {
+ final FormatResult res = new FormatResult();
ByteArrayOutputStream buf = new ByteArrayOutputStream();
final EditList editList;
final FileHeader.PatchType type;
@@ -631,14 +620,15 @@ public class DiffFormatter {
editList = new EditList();
type = PatchType.BINARY;
} else {
- RawText a = rawTextFactory.create(aRaw);
- RawText b = rawTextFactory.create(bRaw);
- editList = new MyersDiff(a, b).getEdits();
+ res.a = rawTextFactory.create(aRaw);
+ res.b = rawTextFactory.create(bRaw);
+ editList = new MyersDiff(res.a, res.b).getEdits();
type = PatchType.UNIFIED;
}
}
- return new FileHeader(buf.toByteArray(), editList, type);
+ res.header = new FileHeader(buf.toByteArray(), editList, type);
+ return res;
}
private int findCombinedEnd(final List<Edit> edits, final int i) {