Search in sources :

Example 6 with DiffTooBigException

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;
}
Also used : VcsException(com.intellij.openapi.vcs.VcsException) DiffTooBigException(com.intellij.diff.comparison.DiffTooBigException) Range(com.intellij.diff.util.Range) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with DiffTooBigException

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);
        }
    };
}
Also used : ComparisonManager(com.intellij.diff.comparison.ComparisonManager) EmptyRunnable(com.intellij.openapi.util.EmptyRunnable) DiffTooBigException(com.intellij.diff.comparison.DiffTooBigException) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DiffTooBigException (com.intellij.diff.comparison.DiffTooBigException)7 LineFragment (com.intellij.diff.fragments.LineFragment)3 ComparisonManager (com.intellij.diff.comparison.ComparisonManager)2 Range (com.intellij.diff.util.Range)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 FairDiffIterable (com.intellij.diff.comparison.iterables.FairDiffIterable)1 DocumentContent (com.intellij.diff.contents.DocumentContent)1 DiffFragment (com.intellij.diff.fragments.DiffFragment)1 DiffUtil (com.intellij.diff.util.DiffUtil)1 Document (com.intellij.openapi.editor.Document)1 DocumentEx (com.intellij.openapi.editor.ex.DocumentEx)1 EditorHighlighter (com.intellij.openapi.editor.highlighter.EditorHighlighter)1 FileType (com.intellij.openapi.fileTypes.FileType)1 EmptyRunnable (com.intellij.openapi.util.EmptyRunnable)1 TextRange (com.intellij.openapi.util.TextRange)1 VcsException (com.intellij.openapi.vcs.VcsException)1 ObjectUtils.assertNotNull (com.intellij.util.ObjectUtils.assertNotNull)1 ArrayList (java.util.ArrayList)1