Search in sources :

Example 6 with Difference

use of com.intellij.history.core.revisions.Difference in project intellij-community by JetBrains.

the class RevisionsAndDiffsTest method testDifferenceForDirectory.

public void testDifferenceForDirectory() throws IOException {
    VirtualFile dir = createDirectory("dir");
    VirtualFile f = createFile("dir/file.txt");
    List<Revision> rr = getRevisionsFor(dir);
    assertEquals(3, rr.size());
    Revision recent = rr.get(0);
    Revision prev = rr.get(1);
    List<Difference> dd = prev.getDifferencesWith(recent);
    assertEquals(1, dd.size());
    Difference d = dd.get(0);
    assertNull(d.getLeft());
    assertEquals("file.txt", d.getRight().getName());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Revision(com.intellij.history.core.revisions.Revision) Difference(com.intellij.history.core.revisions.Difference)

Example 7 with Difference

use of com.intellij.history.core.revisions.Difference in project intellij-community by JetBrains.

the class DirectoryEntry method collectDifferencesWith.

@Override
public void collectDifferencesWith(Entry right, List<Difference> result) {
    DirectoryEntry e = (DirectoryEntry) right;
    if (!getPath().equals(e.getPath())) {
        result.add(new Difference(false, this, e));
    }
    // most often we have the same children, so try processing it directly
    int commonIndex = 0;
    final int myChildrenSize = myChildren.size();
    final int rightChildrenSize = e.myChildren.size();
    final int minChildrenSize = Math.min(myChildrenSize, rightChildrenSize);
    while (commonIndex < minChildrenSize) {
        Entry childEntry = myChildren.get(commonIndex);
        Entry rightChildEntry = e.myChildren.get(commonIndex);
        if (childEntry.getNameId() == rightChildEntry.getNameId() && childEntry.isDirectory() == rightChildEntry.isDirectory()) {
            childEntry.collectDifferencesWith(rightChildEntry, result);
        } else {
            break;
        }
        ++commonIndex;
    }
    if (commonIndex == myChildrenSize && commonIndex == rightChildrenSize)
        return;
    TIntObjectHashMap<Entry> uniqueNameIdToMyChildEntries = new TIntObjectHashMap<>(myChildrenSize - commonIndex);
    for (int i = commonIndex; i < myChildrenSize; ++i) {
        Entry childEntry = myChildren.get(i);
        uniqueNameIdToMyChildEntries.put(childEntry.getNameId(), childEntry);
    }
    TIntObjectHashMap<Entry> uniqueNameIdToRightChildEntries = new TIntObjectHashMap<>(rightChildrenSize - commonIndex);
    TIntObjectHashMap<Entry> myNameIdToRightChildEntries = new TIntObjectHashMap<>(rightChildrenSize - commonIndex);
    for (int i = commonIndex; i < rightChildrenSize; ++i) {
        Entry rightChildEntry = e.myChildren.get(i);
        int rightChildEntryNameId = rightChildEntry.getNameId();
        Entry myChildEntry = uniqueNameIdToMyChildEntries.get(rightChildEntryNameId);
        if (myChildEntry != null && myChildEntry.isDirectory() == rightChildEntry.isDirectory()) {
            uniqueNameIdToMyChildEntries.remove(rightChildEntryNameId);
            myNameIdToRightChildEntries.put(rightChildEntryNameId, rightChildEntry);
        } else {
            uniqueNameIdToRightChildEntries.put(rightChildEntryNameId, rightChildEntry);
        }
    }
    if (!Paths.isCaseSensitive() && uniqueNameIdToMyChildEntries.size() > 0 && uniqueNameIdToRightChildEntries.size() > 0) {
        THashMap<String, Entry> nameToEntryMap = new THashMap<>(uniqueNameIdToMyChildEntries.size(), CaseInsensitiveStringHashingStrategy.INSTANCE);
        uniqueNameIdToMyChildEntries.forEachValue(myChildEntry -> {
            nameToEntryMap.put(myChildEntry.getName(), myChildEntry);
            return true;
        });
        uniqueNameIdToRightChildEntries.forEachValue(rightChildEntry -> {
            Entry myChildEntry = nameToEntryMap.get(rightChildEntry.getName());
            if (myChildEntry != null && rightChildEntry.isDirectory() == myChildEntry.isDirectory()) {
                myNameIdToRightChildEntries.put(myChildEntry.getNameId(), rightChildEntry);
                uniqueNameIdToMyChildEntries.remove(myChildEntry.getNameId());
                uniqueNameIdToRightChildEntries.remove(rightChildEntry.getNameId());
            }
            return true;
        });
    }
    for (Entry child : e.myChildren) {
        if (uniqueNameIdToRightChildEntries.containsKey(child.getNameId())) {
            child.collectCreatedDifferences(result);
        }
    }
    for (Entry child : myChildren) {
        if (uniqueNameIdToMyChildEntries.containsKey(child.getNameId())) {
            child.collectDeletedDifferences(result);
        } else {
            Entry itsChild = myNameIdToRightChildEntries.get(child.getNameId());
            if (itsChild != null)
                child.collectDifferencesWith(itsChild, result);
        }
    }
}
Also used : THashMap(gnu.trove.THashMap) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) Difference(com.intellij.history.core.revisions.Difference)

Example 8 with Difference

use of com.intellij.history.core.revisions.Difference in project intellij-community by JetBrains.

the class DifferenceReverter method getFilesToClearROStatus.

@Override
protected List<VirtualFile> getFilesToClearROStatus() throws IOException {
    LinkedHashSet<VirtualFile> files = new LinkedHashSet<>();
    for (Difference each : myDiffs) {
        Entry l = each.getLeft();
        Entry r = each.getRight();
        VirtualFile f = l == null ? null : myGateway.findVirtualFile(l.getPath());
        if (f != null)
            files.add(f);
        f = r == null ? null : myGateway.findVirtualFile(r.getPath());
        if (f != null)
            files.add(f);
    }
    return new ArrayList<>(files);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Entry(com.intellij.history.core.tree.Entry) ArrayList(java.util.ArrayList) Difference(com.intellij.history.core.revisions.Difference)

Example 9 with Difference

use of com.intellij.history.core.revisions.Difference in project intellij-community by JetBrains.

the class HistoryDialogModel method getChanges.

public List<Change> getChanges() {
    List<Difference> dd = getDifferences();
    List<Change> result = new ArrayList<>();
    for (Difference d : dd) {
        result.add(createChange(d));
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) Difference(com.intellij.history.core.revisions.Difference) Change(com.intellij.openapi.vcs.changes.Change)

Example 10 with Difference

use of com.intellij.history.core.revisions.Difference in project intellij-community by JetBrains.

the class DifferenceReverter method doRevert.

public void doRevert(boolean revertContentChanges) throws IOException {
    Set<String> vetoedFiles = new THashSet<>();
    for (Difference each : ContainerUtil.iterateBackward(myDiffs)) {
        Entry l = each.getLeft();
        Entry r = each.getRight();
        if (l == null) {
            revertCreation(r, vetoedFiles);
            continue;
        }
        vetoedFiles.add(l.getPath());
        if (r == null) {
            revertDeletion(l);
            continue;
        }
        VirtualFile file = myGateway.findOrCreateFileSafely(r.getPath(), r.isDirectory());
        revertRename(l, file);
        if (revertContentChanges)
            revertContentChange(l, file);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Entry(com.intellij.history.core.tree.Entry) Difference(com.intellij.history.core.revisions.Difference) THashSet(gnu.trove.THashSet)

Aggregations

Difference (com.intellij.history.core.revisions.Difference)15 Revision (com.intellij.history.core.revisions.Revision)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 ArrayList (java.util.ArrayList)4 Entry (com.intellij.history.core.tree.Entry)3 DirectoryChangeModel (com.intellij.history.integration.ui.models.DirectoryChangeModel)2 Change (com.intellij.openapi.vcs.changes.Change)2 Content (com.intellij.history.core.Content)1 StoredContent (com.intellij.history.core.StoredContent)1 DirectoryEntry (com.intellij.history.core.tree.DirectoryEntry)1 THashMap (gnu.trove.THashMap)1 THashSet (gnu.trove.THashSet)1 TIntObjectHashMap (gnu.trove.TIntObjectHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Test (org.junit.Test)1