@Override public void rebuildList() { if (myInRebuildList) return; try { myInRebuildList = true; if (myChangesToDisplay == null) { // changes set not fixed === local changes final ChangeListManager manager = ChangeListManager.getInstance(myProject); myChangeListsMap = new HashMap<Change, LocalChangeList>(); final List<LocalChangeList> lists = manager.getChangeListsCopy(); Collection<Change> allChanges = new ArrayList<Change>(); for (LocalChangeList list : lists) { final Collection<Change> changes = list.getChanges(); allChanges.addAll(changes); for (Change change : changes) { myChangeListsMap.put(change, list); } } myAllChanges = allChanges; // refresh selected list also updateListsInChooser(); } super.rebuildList(); if (myRebuildListListener != null) { myRebuildListListener.run(); } } finally { myInRebuildList = false; } }
@Nullable public LocalChangeList listForChange(final Change change) { for (LocalChangeList list : myMap.values()) { if (list.getChanges().contains(change)) return list.copy(); } return null; }
public Collection<Change> getAllChanges() { final Collection<Change> changes = new HashSet<Change>(); for (LocalChangeList list : myMap.values()) { changes.addAll(list.getChanges()); } return changes; }
public void processChangeLists(final List<LocalChangeList> lists) { final ProjectLevelVcsManager plVcsManager = ProjectLevelVcsManager.getInstanceChecked(myProject); plVcsManager.startBackgroundVcsOperation(); try { final SVNChangelistClient client = createChangelistClient(); for (LocalChangeList list : lists) { if (!list.isDefault()) { final Collection<Change> changes = list.getChanges(); for (Change change : changes) { correctListForRevision( plVcsManager, change.getBeforeRevision(), client, list.getName()); correctListForRevision(plVcsManager, change.getAfterRevision(), client, list.getName()); } } } } finally { final Application appManager = ApplicationManager.getApplication(); if (appManager.isDispatchThread()) { appManager.executeOnPooledThread( new Runnable() { @Override public void run() { plVcsManager.stopBackgroundVcsOperation(); } }); } else { plVcsManager.stopBackgroundVcsOperation(); } } }
private void preparation() { for (LocalChangeList list : myMap.values()) { final Collection<Change> managerChanges = list.getChanges(); final LocalChangeList copy = list.copy(); for (Change change : managerChanges) { myInternalMap.put(keyForChange(change), copy); } } }
private Intersection getMergeAllIntersection(List<LocalChangeList> localChangeLists) { final Intersection intersection = new Intersection(); for (LocalChangeList localChangeList : localChangeLists) { final Collection<Change> localChanges = localChangeList.getChanges(); for (Change localChange : localChanges) { intersection.add(localChangeList.getName(), localChangeList.getComment(), localChange); } } return intersection; }
public LocalChangeList getListCopy(@NotNull final VirtualFile file) { for (LocalChangeList list : myMap.values()) { for (Change change : list.getChanges()) { if (change.getAfterRevision() != null && Comparing.equal(change.getAfterRevision().getFile().getVirtualFile(), file)) { return list.copy(); } if (change.getBeforeRevision() != null && Comparing.equal(change.getBeforeRevision().getFile().getVirtualFile(), file)) { return list.copy(); } } } return null; }
@Nullable public Change getChangeForPath(final FilePath file) { for (LocalChangeList list : myMap.values()) { for (Change change : list.getChanges()) { final ContentRevision afterRevision = change.getAfterRevision(); if (afterRevision != null && afterRevision.getFile().equals(file)) { return change; } final ContentRevision beforeRevision = change.getBeforeRevision(); if (beforeRevision != null && beforeRevision.getFile().equals(file)) { return change; } } } return null; }
public void removeRegisteredChangeFor(FilePath path) { myIdx.remove(path); for (LocalChangeList list : myMap.values()) { for (Change change : list.getChanges()) { final ContentRevision afterRevision = change.getAfterRevision(); if (afterRevision != null && afterRevision.getFile().equals(path)) { ((LocalChangeListImpl) list).removeChange(change); return; } final ContentRevision beforeRevision = change.getBeforeRevision(); if (beforeRevision != null && beforeRevision.getFile().equals(path)) { ((LocalChangeListImpl) list).removeChange(change); return; } } } }
public boolean removeChangeList(@NotNull String name) { final LocalChangeList list = myMap.get(name); if (list == null) { return false; } if (list.isDefault()) { throw new RuntimeException( new IncorrectOperationException("Cannot remove default changelist")); } final String listName = list.getName(); for (Change change : list.getChanges()) { ((LocalChangeListImpl) myDefault).addChange(change); } final LocalChangeList removed = myMap.remove(listName); return true; }
@Nullable private Intersection checkIntersection( @Nullable final List<CommittedChangeList> lists, List<LocalChangeList> localChangeLists) { if (lists == null || lists.isEmpty()) { return null; } final Set<FilePath> mergePaths = new HashSet<FilePath>(); for (CommittedChangeList list : lists) { final SvnChangeList svnList = (SvnChangeList) list; final List<String> paths = new ArrayList<String>(svnList.getAddedPaths()); paths.addAll(svnList.getChangedPaths()); paths.addAll(svnList.getDeletedPaths()); for (String path : paths) { final File localPath = getLocalPath(path); if (localPath != null) { mergePaths.add(new FilePathImpl(localPath, false)); } } } final Intersection intersection = new Intersection(); for (LocalChangeList localChangeList : localChangeLists) { final Collection<Change> localChanges = localChangeList.getChanges(); for (Change localChange : localChanges) { final FilePath before = localChange.getBeforeRevision() == null ? null : localChange.getBeforeRevision().getFile(); final FilePath after = localChange.getAfterRevision() == null ? null : localChange.getAfterRevision().getFile(); if ((before != null && mergePaths.contains(before)) || (after != null && mergePaths.contains(after))) { intersection.add(localChangeList.getName(), localChangeList.getComment(), localChange); } } } return intersection; }
public void notifyDoneProcessingChanges(final ChangeListListener dispatcher) { List<ChangeList> changedLists = new ArrayList<ChangeList>(); final Map<LocalChangeListImpl, List<Change>> removedChanges = new HashMap<LocalChangeListImpl, List<Change>>(); final Map<LocalChangeListImpl, List<Change>> addedChanges = new HashMap<LocalChangeListImpl, List<Change>>(); for (LocalChangeList list : myMap.values()) { final List<Change> removed = new ArrayList<Change>(); final List<Change> added = new ArrayList<Change>(); final LocalChangeListImpl listImpl = (LocalChangeListImpl) list; if (listImpl.doneProcessingChanges(removed, added)) { changedLists.add(list); } if (!removed.isEmpty()) { removedChanges.put(listImpl, removed); } if (!added.isEmpty()) { addedChanges.put(listImpl, added); } } for (Map.Entry<LocalChangeListImpl, List<Change>> entry : removedChanges.entrySet()) { dispatcher.changesRemoved(entry.getValue(), entry.getKey()); } for (Map.Entry<LocalChangeListImpl, List<Change>> entry : addedChanges.entrySet()) { dispatcher.changesAdded(entry.getValue(), entry.getKey()); } for (ChangeList changeList : changedLists) { dispatcher.changeListChanged(changeList); } mySwitchedHolder.calculateChildren(); for (String name : myListsToDisappear) { final LocalChangeList changeList = myMap.get(name); if ((changeList != null) && changeList.getChanges().isEmpty() && (!changeList.isReadOnly()) && (!changeList.isDefault())) { removeChangeList(name); } } myListsToDisappear.clear(); }
private void checkForMultipleCopiesNotMove(boolean somethingChanged) { final MultiMap<FilePath, Pair<Change, String>> moves = new MultiMap<FilePath, Pair<Change, String>>() { @NotNull protected Collection<Pair<Change, String>> createCollection() { return new LinkedList<Pair<Change, String>>(); } }; for (LocalChangeList changeList : myMap.values()) { final Collection<Change> changes = changeList.getChanges(); for (Change change : changes) { if (change.isMoved() || change.isRenamed()) { moves.putValue( change.getBeforeRevision().getFile(), Pair.create(change, changeList.getName())); } } } for (FilePath filePath : moves.keySet()) { final List<Pair<Change, String>> copies = (List<Pair<Change, String>>) moves.get(filePath); if (copies.size() == 1) continue; Collections.sort(copies, MyChangesAfterRevisionComparator.getInstance()); for (int i = 0; i < (copies.size() - 1); i++) { somethingChanged = true; final Pair<Change, String> item = copies.get(i); final Change oldChange = item.getFirst(); final Change newChange = new Change(null, oldChange.getAfterRevision()); final LocalChangeListImpl list = (LocalChangeListImpl) myMap.get(item.getSecond()); list.removeChange(oldChange); list.addChange(newChange); final VcsKey key = myIdx.getVcsFor(oldChange); myIdx.changeRemoved(oldChange); myIdx.changeAdded(newChange, key); } } if (somethingChanged) { FileStatusManager.getInstance(myProject).fileStatusesChanged(); } }
@Nullable public String listNameIfOnlyOne(final @Nullable Change[] changes) { if (changes == null || changes.length == 0) { return null; } final Change first = changes[0]; for (LocalChangeList list : myMap.values()) { final Collection<Change> listChanges = list.getChanges(); if (listChanges.contains(first)) { // must contain all other for (int i = 1; i < changes.length; i++) { final Change change = changes[i]; if (!listChanges.contains(change)) { return null; } } return list.getName(); } } return null; }
@NotNull public List<VirtualFile> getAffectedFiles() { final Set<VirtualFile> result = ContainerUtil.newLinkedHashSet(); for (LocalChangeList list : myMap.values()) { for (Change change : list.getChanges()) { final ContentRevision before = change.getBeforeRevision(); final ContentRevision after = change.getAfterRevision(); if (before != null) { final VirtualFile file = before.getFile().getVirtualFile(); if (file != null) { result.add(file); } } if (after != null) { final VirtualFile file = after.getFile().getVirtualFile(); if (file != null) { result.add(file); } } } } return new ArrayList<VirtualFile>(result); }
private void createChangelist(final ContinuationPause context) { final ChangeListManager listManager = ChangeListManager.getInstance(myProject); String name = myTitle; int i = 1; boolean updateDefaultList = false; while (true) { final LocalChangeList changeList = listManager.findChangeList(name); if (changeList == null) { final LocalChangeList newList = listManager.addChangeList(name, null); listManager.setDefaultChangeList(newList); updateDefaultList = true; break; } if (changeList.getChanges().isEmpty()) { if (!changeList.isDefault()) { listManager.setDefaultChangeList(changeList); updateDefaultList = true; } break; } name = myTitle + " (" + i + ")"; ++i; } if (updateDefaultList) { context.suspend(); listManager.invokeAfterUpdate( new Runnable() { public void run() { context.ping(); } }, InvokeAfterUpdateMode.BACKGROUND_NOT_CANCELLABLE_NOT_AWT, "", ModalityState.NON_MODAL); } }