@Nullable public LocalChangeList listForChange(final Change change) { for (LocalChangeList list : myMap.values()) { if (list.getChanges().contains(change)) return list.copy(); } return null; }
@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; } }
public Collection<Change> getAllChanges() { final Collection<Change> changes = new HashSet<Change>(); for (LocalChangeList list : myMap.values()) { changes.addAll(list.getChanges()); } return changes; }
public List<LocalChangeList> getListsCopy() { final List<LocalChangeList> result = new ArrayList<LocalChangeList>(); for (LocalChangeList list : myMap.values()) { result.add(list.copy()); } return result; }
private ChangeListWorker(final ChangeListWorker worker) { myProject = worker.myProject; myMap = new LinkedHashMap<String, LocalChangeList>(); myIdx = new ChangeListsIndexes(worker.myIdx); myLocallyDeleted = worker.myLocallyDeleted.copy(); mySwitchedHolder = worker.mySwitchedHolder.copy(); myDelta = worker.myDelta; myListsToDisappear = new LinkedList<String>(worker.myListsToDisappear); LocalChangeList defaultList = null; for (LocalChangeList changeList : worker.myMap.values()) { final LocalChangeList copy = changeList.copy(); final String changeListName = copy.getName(); myMap.put(changeListName, copy); if (copy.isDefault()) { defaultList = copy; } } if (defaultList == null) { LOG.info("default list not found when copy"); defaultList = myMap.get(worker.getDefaultListName()); } if (defaultList == null) { LOG.info("default list not found when copy in original object too"); if (!myMap.isEmpty()) { defaultList = myMap.values().iterator().next(); } else { // can be when there's no vcs configured /// LOG.error("no changelists at all"); } } myDefault = defaultList; }
protected void processInChange(Couple<String> key, Change change) { final LocalChangeList list = myInternalMap.get(key); if (list != null) { myIncludedListsCopies.put(list.getName(), list); myValidChanges.add(change); } }
public boolean setReadOnly(final String name, final boolean value) { final LocalChangeList list = myMap.get(name); if (list != null) { list.setReadOnly(value); } return list != null; }
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); } } }
@Nullable public LocalChangeList getChangeList(String id) { for (LocalChangeList changeList : myMap.values()) { if (changeList.getId().equals(id)) { return changeList.copy(); } } return null; }
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; }
@Override public void trackContext(LocalChangeList changeList) { ChangeListInfo changeListInfo = new ChangeListInfo(changeList); String changeListName = changeList.getName(); LocalTaskImpl task = createLocalTask(changeListName); task.addChangelist(changeListInfo); addTask(task); if (changeList.isDefault()) { activateTask(task, false); } }
protected void processInChange(Couple<String> key, Change change) { LocalChangeList tmpList = myInternalMap.get(key); if (tmpList == null) { tmpList = myDefaultCopy; } final String tmpName = tmpList.getName(); List<Change> list = myListToChangesMap.get(tmpName); if (list == null) { list = new ArrayList<Change>(); myListToChangesMap.put(tmpName, list); myIncludedListsCopies.put(tmpName, tmpList); } list.add(change); }
private void createChangeList(LocalTask task, String name, @Nullable String comment) { LocalChangeList changeList = myChangeListManager.findChangeList(name); if (changeList == null) { changeList = myChangeListManager.addChangeList(name, comment); } else { final LocalTask associatedTask = getAssociatedTask(changeList); if (associatedTask != null) { associatedTask.removeChangelist(new ChangeListInfo(changeList)); } changeList.setComment(comment); } task.addChangelist(new ChangeListInfo(changeList)); myChangeListManager.setDefaultChangeList(changeList); }
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; }
LocalChangeList addChangeList( String id, @NotNull final String name, @Nullable final String description, final boolean inUpdate, @Nullable Object data) { final boolean contains = myMap.containsKey(name); LOG.assertTrue(!contains, "Attempt to create duplicate changelist " + name); final LocalChangeListImpl newList = (LocalChangeListImpl) LocalChangeList.createEmptyChangeList(myProject, name); newList.setData(data); if (description != null) { newList.setCommentImpl(description); } if (id != null) { newList.setId(id); } myMap.put(name, newList); if (inUpdate) { // scope is not important: nothing had been added jet, nothing to move to "old state" members newList.startProcessingChanges( myProject, null); // this is executed only when use through GATE } return newList.copy(); }
public boolean editName(@NotNull final String fromName, @NotNull final String toName) { if (fromName.equals(toName)) return false; final LocalChangeList list = myMap.get(fromName); final boolean canEdit = list != null && (!list.isReadOnly()); if (canEdit) { final LocalChangeListImpl listImpl = (LocalChangeListImpl) list; listImpl.setNameImpl(toName); myMap.remove(fromName); myMap.put(toName, list); final ChangeListEditHandler editHandler = listImpl.getEditHandler(); if (editHandler != null) { listImpl.setCommentImpl( editHandler.changeCommentOnChangeName(toName, listImpl.getComment())); } } return canEdit; }
@Nullable private static Consumer<Collection<FilePath>> createMover( final Project project, final LocalChangeList targetChangeList) { final ChangeListManager clm = ChangeListManager.getInstance(project); if (targetChangeList == null || clm.getDefaultListName().equals(targetChangeList.getName())) return null; return new FilesMover(clm, targetChangeList); }
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; }
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; } } } }
@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(); }
@Override public void onChangeListSelected(LocalChangeList list) { Object data = list.getData(); if (data instanceof VcsFullCommitDetails) { VcsFullCommitDetails commit = (VcsFullCommitDetails) data; String author = String.format("%s <%s>", commit.getAuthor().getName(), commit.getAuthor().getEmail()); myAuthor.getEditor().setItem(author); myAuthorDate = new Date(commit.getTime()); } }
@Nullable public MultiMap<LocalChangeList, Change> moveChangesTo( final String name, final Change[] changes) { final LocalChangeListImpl changeList = (LocalChangeListImpl) myMap.get(name); if (changeList != null) { final MultiMap<LocalChangeList, Change> result = new MultiMap<LocalChangeList, Change>(); for (LocalChangeList list : myMap.values()) { if (list.equals(changeList)) continue; for (Change change : changes) { final Change removedChange = ((LocalChangeListImpl) list).removeChange(change); if (removedChange != null) { changeList.addChange(removedChange); result.putValue(list, removedChange); } } } return result; } return null; }
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 @Override public LocalTask getAssociatedTask(LocalChangeList list) { for (LocalTask task : getLocalTasks()) { for (ChangeListInfo changeListInfo : task.getChangeLists()) { if (changeListInfo.id.equals(list.getId())) { return task; } } } return null; }
@Nullable public String editComment(@NotNull final String fromName, final String newComment) { final LocalChangeList list = myMap.get(fromName); if (list != null) { final String oldComment = list.getComment(); if (!Comparing.equal(oldComment, newComment)) { final LocalChangeListImpl listImpl = (LocalChangeListImpl) list; listImpl.setCommentImpl(newComment); final ChangeListEditHandler editHandler = listImpl.getEditHandler(); if (editHandler != null) { listImpl.setNameImpl( editHandler.changeNameOnChangeComment(listImpl.getName(), listImpl.getComment())); if (!fromName.equals(listImpl.getName())) { myMap.remove(fromName); myMap.put(listImpl.getName(), list); } } } return oldComment; } 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); }
@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; }