Refactor type dependent unified diff displaying into separate functions

Thereby we can better see the overall flow of control.

Change-Id: I7c49da641cca2b5ec1fd85026f7e9df5a87ba32d
This commit is contained in:
Christian Aistleitner
2013-04-24 16:30:26 +02:00
parent 250caf1d2b
commit 4c13fe4fbf

View File

@@ -228,87 +228,12 @@ public class UnifiedDiffTable extends AbstractPatchContentTable {
final ArrayList<PatchLine> lines = new ArrayList<PatchLine>();
if (script.getDisplayMethodA() == DisplayMethod.IMG
|| script.getDisplayMethodB() == DisplayMethod.IMG) {
final String rawBase = GWT.getHostPageBaseURL() + "cat/";
nc.openTr();
nc.setAttribute("valign", "center");
nc.setAttribute("align", "center");
nc.openTd();
nc.nbsp();
nc.closeTd();
nc.openTd();
nc.nbsp();
nc.closeTd();
nc.openTd();
nc.nbsp();
nc.closeTd();
nc.openTd();
if (script.getDisplayMethodA() == DisplayMethod.IMG) {
if (idSideA == null) {
appendImgTag(nc, rawBase + KeyUtil.encode(patchKey.toString()) + "^1");
} else {
Patch.Key k = new Patch.Key(idSideA, patchKey.get());
appendImgTag(nc, rawBase + KeyUtil.encode(k.toString()) + "^0");
}
}
if (script.getDisplayMethodB() == DisplayMethod.IMG) {
appendImgTag(nc, rawBase + KeyUtil.encode(patchKey.toString()) + "^0");
}
nc.closeTd();
nc.closeTr();
appendImageDifferences(script, nc);
}
if (!isDisplayBinary) {
final SparseHtmlFile a = getSparseHtmlFileA(script);
final SparseHtmlFile b = getSparseHtmlFileB(script);
if (hasDifferences(script)) {
final boolean syntaxHighlighting =
script.getDiffPrefs().isSyntaxHighlighting();
for (final EditList.Hunk hunk : script.getHunks()) {
appendHunkHeader(nc, hunk);
while (hunk.next()) {
if (hunk.isContextLine()) {
openLine(nc);
appendLineNumberForSideA(nc, hunk.getCurA());
appendLineNumberForSideB(nc, hunk.getCurB());
appendLineText(nc, false, CONTEXT, a, hunk.getCurA());
closeLine(nc);
hunk.incBoth();
lines.add(new PatchLine(CONTEXT, hunk.getCurA(), hunk.getCurB()));
} else if (hunk.isDeletedA()) {
openLine(nc);
appendLineNumberForSideA(nc, hunk.getCurA());
padLineNumberForSideB(nc);
appendLineText(nc, syntaxHighlighting, DELETE, a, hunk.getCurA());
closeLine(nc);
hunk.incA();
lines.add(new PatchLine(DELETE, hunk.getCurA(), -1));
if (a.size() == hunk.getCurA()
&& script.getA().isMissingNewlineAtEnd()) {
appendNoLF(nc);
}
} else if (hunk.isInsertedB()) {
openLine(nc);
padLineNumberForSideA(nc);
appendLineNumberForSideB(nc, hunk.getCurB());
appendLineText(nc, syntaxHighlighting, INSERT, b, hunk.getCurB());
closeLine(nc);
hunk.incB();
lines.add(new PatchLine(INSERT, -1, hunk.getCurB()));
if (b.size() == hunk.getCurB()
&& script.getB().isMissingNewlineAtEnd()) {
appendNoLF(nc);
}
}
}
}
appendTextDifferences(script, nc, lines);
}
}
if (!hasDifferences(script)) {
@@ -347,6 +272,91 @@ public class UnifiedDiffTable extends AbstractPatchContentTable {
}
}
private void appendImageDifferences(final PatchScript script,
final SafeHtmlBuilder nc) {
final String rawBase = GWT.getHostPageBaseURL() + "cat/";
nc.openTr();
nc.setAttribute("valign", "center");
nc.setAttribute("align", "center");
nc.openTd();
nc.nbsp();
nc.closeTd();
nc.openTd();
nc.nbsp();
nc.closeTd();
nc.openTd();
nc.nbsp();
nc.closeTd();
nc.openTd();
if (script.getDisplayMethodA() == DisplayMethod.IMG) {
if (idSideA == null) {
appendImgTag(nc, rawBase + KeyUtil.encode(patchKey.toString()) + "^1");
} else {
Patch.Key k = new Patch.Key(idSideA, patchKey.get());
appendImgTag(nc, rawBase + KeyUtil.encode(k.toString()) + "^0");
}
}
if (script.getDisplayMethodB() == DisplayMethod.IMG) {
appendImgTag(nc, rawBase + KeyUtil.encode(patchKey.toString()) + "^0");
}
nc.closeTd();
nc.closeTr();
}
private void appendTextDifferences(final PatchScript script,
final SafeHtmlBuilder nc, final ArrayList<PatchLine> lines) {
final SparseHtmlFile a = getSparseHtmlFileA(script);
final SparseHtmlFile b = getSparseHtmlFileB(script);
final boolean syntaxHighlighting =
script.getDiffPrefs().isSyntaxHighlighting();
for (final EditList.Hunk hunk : script.getHunks()) {
appendHunkHeader(nc, hunk);
while (hunk.next()) {
if (hunk.isContextLine()) {
openLine(nc);
appendLineNumberForSideA(nc, hunk.getCurA());
appendLineNumberForSideB(nc, hunk.getCurB());
appendLineText(nc, false, CONTEXT, a, hunk.getCurA());
closeLine(nc);
hunk.incBoth();
lines.add(new PatchLine(CONTEXT, hunk.getCurA(), hunk.getCurB()));
} else if (hunk.isDeletedA()) {
openLine(nc);
appendLineNumberForSideA(nc, hunk.getCurA());
padLineNumberForSideB(nc);
appendLineText(nc, syntaxHighlighting, DELETE, a, hunk.getCurA());
closeLine(nc);
hunk.incA();
lines.add(new PatchLine(DELETE, hunk.getCurA(), -1));
if (a.size() == hunk.getCurA()
&& script.getA().isMissingNewlineAtEnd()) {
appendNoLF(nc);
}
} else if (hunk.isInsertedB()) {
openLine(nc);
padLineNumberForSideA(nc);
appendLineNumberForSideB(nc, hunk.getCurB());
appendLineText(nc, syntaxHighlighting, INSERT, b, hunk.getCurB());
closeLine(nc);
hunk.incB();
lines.add(new PatchLine(INSERT, -1, hunk.getCurB()));
if (b.size() == hunk.getCurB()
&& script.getB().isMissingNewlineAtEnd()) {
appendNoLF(nc);
}
}
}
}
}
@Override
public void display(final CommentDetail cd, boolean expandComments) {
if (cd.isEmpty()) {