use of com.intellij.diff.comparison.DiffTooBigException in project intellij-community by JetBrains.
the class TextPatchBuilder method buildModifiedFile.
@Nullable
private TextFilePatch buildModifiedFile(@NotNull AirContentRevision beforeRevision, @NotNull AirContentRevision afterRevision) throws VcsException {
String beforeContent = getContent(beforeRevision);
String afterContent = getContent(afterRevision);
TextFilePatch patch = buildPatchHeading(beforeRevision, afterRevision);
if (beforeContent.equals(afterContent)) {
if (beforeRevision.getPath().getPath().equals(afterRevision.getPath().getPath()))
return null;
// movement
patch.addHunk(new PatchHunk(0, 0, 0, 0));
return patch;
}
if (beforeContent.isEmpty()) {
patch.addHunk(createWholeFileHunk(afterContent, true, true));
return patch;
}
if (afterContent.isEmpty()) {
patch.addHunk(createWholeFileHunk(beforeContent, false, true));
return patch;
}
List<String> beforeLines = tokenize(beforeContent);
List<String> afterLines = tokenize(afterContent);
boolean beforeNoNewlineAtEOF = !beforeContent.endsWith("\n");
boolean afterNoNewlineAtEOF = !afterContent.endsWith("\n");
List<Range> fragments;
try {
fragments = compareLines(beforeLines, afterLines, beforeNoNewlineAtEOF, afterNoNewlineAtEOF);
} catch (DiffTooBigException e) {
throw new VcsException("File '" + myBasePath + "' is too big and there are too many changes to build diff", e);
}
int hunkStart = 0;
while (hunkStart < fragments.size()) {
List<Range> hunkFragments = getAdjacentFragments(fragments, hunkStart);
patch.addHunk(createHunk(hunkFragments, beforeLines, afterLines, beforeNoNewlineAtEOF, afterNoNewlineAtEOF));
hunkStart += hunkFragments.size();
}
return patch;
}
use of com.intellij.diff.comparison.DiffTooBigException in project intellij-community by JetBrains.
the class SvnPropertiesDiffViewer method performRediff.
@NotNull
@Override
protected Runnable performRediff(@NotNull ProgressIndicator indicator) {
if (!myFirstRediff)
return new EmptyRunnable();
myFirstRediff = false;
for (DiffChange change : myDiffChanges) {
PropertyRecord record = change.getRecord();
String before = record.getBefore();
String after = record.getAfter();
assert before != null || after != null;
if (before == null) {
change.setFragments(createEverythingChanged(0, after.length(), 0, StringUtil.countNewLines(after) + 1));
continue;
}
if (after == null) {
change.setFragments(createEverythingChanged(before.length(), 0, StringUtil.countNewLines(before) + 1, 0));
continue;
}
try {
ComparisonManager manager = ComparisonManager.getInstance();
change.setFragments(manager.squash(manager.compareLinesInner(before, after, ComparisonPolicy.DEFAULT, indicator)));
} catch (DiffTooBigException e) {
change.setFragments(createEverythingChanged(before.length(), after.length(), StringUtil.countNewLines(before) + 1, StringUtil.countNewLines(after) + 1));
}
}
return () -> {
for (DiffChange change : myDiffChanges) {
setupHighlighting(change, Side.LEFT);
setupHighlighting(change, Side.RIGHT);
}
};
}
Aggregations