diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListsIndexes.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListsIndexes.java index 3fbcacb42280..897b7f16627e 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListsIndexes.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListsIndexes.java @@ -121,33 +121,37 @@ public class ChangeListsIndexes { * (for RemoteRevisionsCache and annotation listener) */ public void getDelta(final ChangeListsIndexes newIndexes, - final Set toRemove, + Set toRemove, Set toAdd, Set> toModify) { - // this is old - final Set oldKeySet = newHashSet(myMap.keySet()); - final Set toRemoveSet = newHashSet(oldKeySet); - final Set newKeySet = newIndexes.myMap.keySet(); - final Set toAddSet = newHashSet(newKeySet); - toRemoveSet.removeAll(newKeySet); - toAddSet.removeAll(oldKeySet); - // those that modified - oldKeySet.removeAll(toRemoveSet); + TreeMap oldMap = myMap; + TreeMap newMap = newIndexes.myMap; + Set oldFiles = oldMap.keySet(); + Set newFiles = newMap.keySet(); + + final Set toRemoveSet = newHashSet(oldFiles); + toRemoveSet.removeAll(newFiles); + + final Set toAddSet = newHashSet(newFiles); + toAddSet.removeAll(oldFiles); + + final Set toModifySet = newHashSet(oldFiles); + toModifySet.removeAll(toRemoveSet); for (FilePath s : toRemoveSet) { - final Data data = myMap.get(s); + final Data data = oldMap.get(s); toRemove.add(fromPairAndPath(s, data)); } for (FilePath s : toAddSet) { - final Data data = newIndexes.myMap.get(s); + final Data data = newMap.get(s); toAdd.add(fromPairAndPath(s, data)); } - for (FilePath s : oldKeySet) { - final Data old = myMap.get(s); - final Data newOne = newIndexes.myMap.get(s); - assert old != null && newOne != null; - if (!old.sameRevisions(newOne)) { - toModify.add(new BeforeAfter<>(fromPairAndPath(s, old), fromPairAndPath(s, newOne))); + for (FilePath s : toModifySet) { + final Data oldData = oldMap.get(s); + final Data newData = newMap.get(s); + assert oldData != null && newData != null; + if (!oldData.sameRevisions(newData)) { + toModify.add(new BeforeAfter<>(fromPairAndPath(s, oldData), fromPairAndPath(s, newData))); } } }