use of com.google.gerrit.prettify.common.EditHunk in project gerrit by GerritCodeReview.
the class DiffContentCalculator method packContent.
private DiffContent packContent(TextSource a, TextSource b, boolean ignoredWhitespace, ImmutableList<Edit> edits) {
SparseFileContentBuilder diffA = new SparseFileContentBuilder(a.size());
SparseFileContentBuilder diffB = new SparseFileContentBuilder(b.size());
if (!edits.isEmpty()) {
EditHunk hunk = new EditHunk(edits, a.size(), b.size());
while (hunk.next()) {
if (hunk.isUnmodifiedLine()) {
String lineA = a.getSourceLine(hunk.getCurA());
diffA.addLine(hunk.getCurA(), lineA);
if (ignoredWhitespace) {
// If we ignored whitespace in some form, also get the line
// from b when it does not exactly match the line from a.
//
String lineB = b.getSourceLine(hunk.getCurB());
if (!lineA.equals(lineB)) {
diffB.addLine(hunk.getCurB(), lineB);
}
}
hunk.incBoth();
continue;
}
if (hunk.isDeletedA()) {
a.copyLineTo(diffA, hunk.getCurA());
hunk.incA();
}
if (hunk.isInsertedB()) {
b.copyLineTo(diffB, hunk.getCurB());
hunk.incB();
}
}
}
return new DiffContent(diffA.build(), diffB.build());
}
Aggregations