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());
}
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);
}
}
}
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);
}
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;
}
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);
}
}
Aggregations