Search in sources :

Example 1 with LocalChangesUnderRoots

use of com.intellij.openapi.vcs.impl.LocalChangesUnderRoots in project intellij-community by JetBrains.

the class GitShelveChangesSaver method save.

@Override
protected void save(@NotNull Collection<VirtualFile> rootsToSave) throws VcsException {
    LOG.info("save " + rootsToSave);
    final Map<String, Map<VirtualFile, Collection<Change>>> lists = new LocalChangesUnderRoots(myChangeManager, myVcsManager).getChangesByLists(rootsToSave);
    String oldProgressTitle = myProgressIndicator.getText();
    myProgressIndicator.setText(GitBundle.getString("update.shelving.changes"));
    List<VcsException> exceptions = new ArrayList<>(1);
    myShelvedLists = new HashMap<>();
    for (Map.Entry<String, Map<VirtualFile, Collection<Change>>> entry : lists.entrySet()) {
        final Map<VirtualFile, Collection<Change>> map = entry.getValue();
        final Set<Change> changes = new HashSet<>();
        for (Collection<Change> changeCollection : map.values()) {
            changes.addAll(changeCollection);
        }
        if (!changes.isEmpty()) {
            final ShelvedChangeList list = GitShelveUtils.shelveChanges(myProject, myShelveManager, changes, myStashMessage + " [" + entry.getKey() + "]", exceptions, false, true);
            myShelvedLists.put(entry.getKey(), list);
        }
    }
    if (!exceptions.isEmpty()) {
        LOG.info("save " + exceptions, exceptions.get(0));
        // no restore here since during shelving changes are not rolled back...
        myShelvedLists = null;
        throw exceptions.get(0);
    } else {
        for (VirtualFile root : rootsToSave) {
            GitRollbackEnvironment.resetHardLocal(myProject, root);
        }
    }
    myProgressIndicator.setText(oldProgressTitle);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ShelvedChangeList(com.intellij.openapi.vcs.changes.shelf.ShelvedChangeList) Change(com.intellij.openapi.vcs.changes.Change) LocalChangesUnderRoots(com.intellij.openapi.vcs.impl.LocalChangesUnderRoots) VcsException(com.intellij.openapi.vcs.VcsException)

Example 2 with LocalChangesUnderRoots

use of com.intellij.openapi.vcs.impl.LocalChangesUnderRoots in project intellij-community by JetBrains.

the class GitUpdateProcess method tryFastForwardMergeForRebaseUpdaters.

@NotNull
private Map<VirtualFile, GitUpdater> tryFastForwardMergeForRebaseUpdaters(@NotNull Map<VirtualFile, GitUpdater> updaters) {
    Map<VirtualFile, GitUpdater> modifiedUpdaters = new HashMap<>();
    Map<VirtualFile, Collection<Change>> changesUnderRoots = new LocalChangesUnderRoots(myChangeListManager, myVcsManager).getChangesUnderRoots(updaters.keySet());
    for (Map.Entry<VirtualFile, GitUpdater> updaterEntry : updaters.entrySet()) {
        VirtualFile root = updaterEntry.getKey();
        GitUpdater updater = updaterEntry.getValue();
        Collection<Change> changes = changesUnderRoots.get(root);
        LOG.debug("Changes under root '" + getShortVcsRootName(myProject, root) + "': " + changes);
        if (updater instanceof GitRebaseUpdater && changes != null && !changes.isEmpty()) {
            // check only if there are local changes, otherwise stash won't happen anyway and there would be no optimization
            GitRebaseUpdater rebaseUpdater = (GitRebaseUpdater) updater;
            if (rebaseUpdater.fastForwardMerge()) {
                continue;
            }
        }
        modifiedUpdaters.put(root, updater);
    }
    return modifiedUpdaters;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashMap(java.util.HashMap) Collection(java.util.Collection) Change(com.intellij.openapi.vcs.changes.Change) LocalChangesUnderRoots(com.intellij.openapi.vcs.impl.LocalChangesUnderRoots) HashMap(java.util.HashMap) Map(java.util.Map) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with LocalChangesUnderRoots

use of com.intellij.openapi.vcs.impl.LocalChangesUnderRoots in project intellij-community by JetBrains.

the class LocalChangesUnderRootsTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    myChangeListManager = new MockChangeListManager();
    myBaseDir = myProject.getBaseDir();
    myLocalChangesUnderRoots = new LocalChangesUnderRoots(myChangeListManager, ProjectLevelVcsManager.getInstance(myProject));
}
Also used : MockChangeListManager(com.intellij.testFramework.vcs.MockChangeListManager) LocalChangesUnderRoots(com.intellij.openapi.vcs.impl.LocalChangesUnderRoots)

Aggregations

LocalChangesUnderRoots (com.intellij.openapi.vcs.impl.LocalChangesUnderRoots)3 Change (com.intellij.openapi.vcs.changes.Change)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 VcsException (com.intellij.openapi.vcs.VcsException)1 ShelvedChangeList (com.intellij.openapi.vcs.changes.shelf.ShelvedChangeList)1 MockChangeListManager (com.intellij.testFramework.vcs.MockChangeListManager)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 NotNull (org.jetbrains.annotations.NotNull)1