Search in sources :

Example 1 with ShelvedChangeList

use of com.intellij.openapi.vcs.changes.shelf.ShelvedChangeList 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 ShelvedChangeList

use of com.intellij.openapi.vcs.changes.shelf.ShelvedChangeList in project intellij-community by JetBrains.

the class GitShelveUtils method shelveChanges.

/**
   * Shelve changes
   *
   *
   * @param project       the context project
   * @param shelveManager the shelve manager
   * @param changes       the changes to process
   * @param description   the description of for the shelve
   * @param exceptions    the generated exceptions
   * @param rollback
   * @return created shelved change list or null in case failure
   */
@Nullable
public static ShelvedChangeList shelveChanges(final Project project, final ShelveChangesManager shelveManager, Collection<Change> changes, final String description, final List<VcsException> exceptions, boolean rollback, boolean markToBeDeleted) {
    try {
        ShelvedChangeList shelve = shelveManager.shelveChanges(changes, description, rollback, markToBeDeleted);
        project.getMessageBus().syncPublisher(ShelveChangesManager.SHELF_TOPIC).stateChanged(new ChangeEvent(GitStashUtils.class));
        return shelve;
    } catch (IOException e) {
        //noinspection ThrowableInstanceNeverThrown
        exceptions.add(new VcsException("Shelving changes failed: " + description, e));
        return null;
    } catch (VcsException e) {
        exceptions.add(e);
        return null;
    }
}
Also used : ShelvedChangeList(com.intellij.openapi.vcs.changes.shelf.ShelvedChangeList) ChangeEvent(javax.swing.event.ChangeEvent) VcsException(com.intellij.openapi.vcs.VcsException) IOException(java.io.IOException) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with ShelvedChangeList

use of com.intellij.openapi.vcs.changes.shelf.ShelvedChangeList in project intellij-community by JetBrains.

the class ImportToShelfExecutor method apply.

@Override
public void apply(@NotNull List<FilePatch> remaining, @NotNull final MultiMap<VirtualFile, TextFilePatchInProgress> patchGroupsToApply, @Nullable LocalChangeList localList, @Nullable final String fileName, @Nullable ThrowableComputable<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo) {
    if (fileName == null) {
        LOG.error("Patch file name shouldn't be null");
        return;
    }
    final VcsCatchingRunnable vcsCatchingRunnable = new VcsCatchingRunnable() {

        @Override
        public void runImpl() throws VcsException {
            final VirtualFile baseDir = myProject.getBaseDir();
            final File ioBase = new File(baseDir.getPath());
            final List<FilePatch> allPatches = new ArrayList<>();
            for (VirtualFile virtualFile : patchGroupsToApply.keySet()) {
                final File ioCurrentBase = new File(virtualFile.getPath());
                allPatches.addAll(ContainerUtil.map(patchGroupsToApply.get(virtualFile), new Function<TextFilePatchInProgress, TextFilePatch>() {

                    public TextFilePatch fun(TextFilePatchInProgress patchInProgress) {
                        final TextFilePatch was = patchInProgress.getPatch();
                        was.setBeforeName(PathUtil.toSystemIndependentName(FileUtil.getRelativePath(ioBase, new File(ioCurrentBase, was.getBeforeName()))));
                        was.setAfterName(PathUtil.toSystemIndependentName(FileUtil.getRelativePath(ioBase, new File(ioCurrentBase, was.getAfterName()))));
                        return was;
                    }
                }));
            }
            if (!allPatches.isEmpty()) {
                PatchEP[] patchTransitExtensions = null;
                if (additionalInfo != null) {
                    try {
                        final Map<String, PatchEP> extensions = new HashMap<>();
                        for (Map.Entry<String, Map<String, CharSequence>> entry : additionalInfo.compute().entrySet()) {
                            final String filePath = entry.getKey();
                            Map<String, CharSequence> extToValue = entry.getValue();
                            for (Map.Entry<String, CharSequence> innerEntry : extToValue.entrySet()) {
                                TransitExtension patchEP = (TransitExtension) extensions.get(innerEntry.getKey());
                                if (patchEP == null) {
                                    patchEP = new TransitExtension(innerEntry.getKey());
                                    extensions.put(innerEntry.getKey(), patchEP);
                                }
                                patchEP.put(filePath, innerEntry.getValue());
                            }
                        }
                        Collection<PatchEP> values = extensions.values();
                        patchTransitExtensions = values.toArray(new PatchEP[values.size()]);
                    } catch (PatchSyntaxException e) {
                        VcsBalloonProblemNotifier.showOverChangesView(myProject, "Can not import additional patch info: " + e.getMessage(), MessageType.ERROR);
                    }
                }
                try {
                    final ShelvedChangeList shelvedChangeList = ShelveChangesManager.getInstance(myProject).importFilePatches(fileName, allPatches, patchTransitExtensions);
                    ShelvedChangesViewManager.getInstance(myProject).activateView(shelvedChangeList);
                } catch (IOException e) {
                    throw new VcsException(e);
                }
            }
        }
    };
    ProgressManager.getInstance().runProcessWithProgressSynchronously(vcsCatchingRunnable, "Import Patch to Shelf", true, myProject);
    if (!vcsCatchingRunnable.get().isEmpty()) {
        AbstractVcsHelper.getInstance(myProject).showErrors(vcsCatchingRunnable.get(), IMPORT_TO_SHELF);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ShelvedChangeList(com.intellij.openapi.vcs.changes.shelf.ShelvedChangeList) Function(com.intellij.util.Function) PatchEP(com.intellij.openapi.diff.impl.patch.PatchEP) VcsCatchingRunnable(com.intellij.vcsUtil.VcsCatchingRunnable) IOException(java.io.IOException) TextFilePatch(com.intellij.openapi.diff.impl.patch.TextFilePatch) FilePatch(com.intellij.openapi.diff.impl.patch.FilePatch) PatchSyntaxException(com.intellij.openapi.diff.impl.patch.PatchSyntaxException) TextFilePatch(com.intellij.openapi.diff.impl.patch.TextFilePatch) VcsException(com.intellij.openapi.vcs.VcsException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) MultiMap(com.intellij.util.containers.MultiMap)

Example 4 with ShelvedChangeList

use of com.intellij.openapi.vcs.changes.shelf.ShelvedChangeList in project intellij-community by JetBrains.

the class CreatePatchFromChangesAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    Project project = e.getData(CommonDataKeys.PROJECT);
    final Change[] changes = e.getData(VcsDataKeys.CHANGES);
    if ((changes == null) || (changes.length == 0))
        return;
    String commitMessage = null;
    List<ShelvedChangeList> shelvedChangeLists = ShelvedChangesViewManager.getShelvedLists(e.getDataContext());
    if (!shelvedChangeLists.isEmpty()) {
        commitMessage = shelvedChangeLists.get(0).DESCRIPTION;
    } else {
        ChangeList[] changeLists = e.getData(VcsDataKeys.CHANGE_LISTS);
        if (changeLists != null && changeLists.length > 0) {
            commitMessage = changeLists[0].getComment();
        }
    }
    if (commitMessage == null) {
        commitMessage = e.getData(VcsDataKeys.PRESET_COMMIT_MESSAGE);
    }
    if (commitMessage == null) {
        commitMessage = "";
    }
    List<Change> changeCollection = new ArrayList<>();
    Collections.addAll(changeCollection, changes);
    createPatch(project, commitMessage, changeCollection);
}
Also used : Project(com.intellij.openapi.project.Project) ShelvedChangeList(com.intellij.openapi.vcs.changes.shelf.ShelvedChangeList) ShelvedChangeList(com.intellij.openapi.vcs.changes.shelf.ShelvedChangeList) ArrayList(java.util.ArrayList)

Example 5 with ShelvedChangeList

use of com.intellij.openapi.vcs.changes.shelf.ShelvedChangeList in project intellij-community by JetBrains.

the class GitShelveChangesSaver method load.

@Override
public void load() {
    if (myShelvedLists != null) {
        LOG.info("load ");
        String oldProgressTitle = myProgressIndicator.getText();
        myProgressIndicator.setText(GitBundle.getString("update.unshelving.changes"));
        for (ShelvedChangeList list : myShelvedLists.values()) {
            GitShelveUtils.doSystemUnshelve(myProject, list, myShelveManager, getConflictLeftPanelTitle(), getConflictRightPanelTitle());
        }
        myProgressIndicator.setText(oldProgressTitle);
    }
}
Also used : ShelvedChangeList(com.intellij.openapi.vcs.changes.shelf.ShelvedChangeList)

Aggregations

ShelvedChangeList (com.intellij.openapi.vcs.changes.shelf.ShelvedChangeList)5 VcsException (com.intellij.openapi.vcs.VcsException)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 IOException (java.io.IOException)2 FilePatch (com.intellij.openapi.diff.impl.patch.FilePatch)1 PatchEP (com.intellij.openapi.diff.impl.patch.PatchEP)1 PatchSyntaxException (com.intellij.openapi.diff.impl.patch.PatchSyntaxException)1 TextFilePatch (com.intellij.openapi.diff.impl.patch.TextFilePatch)1 Project (com.intellij.openapi.project.Project)1 Change (com.intellij.openapi.vcs.changes.Change)1 LocalChangesUnderRoots (com.intellij.openapi.vcs.impl.LocalChangesUnderRoots)1 Function (com.intellij.util.Function)1 MultiMap (com.intellij.util.containers.MultiMap)1 VcsCatchingRunnable (com.intellij.vcsUtil.VcsCatchingRunnable)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 ChangeEvent (javax.swing.event.ChangeEvent)1 Nullable (org.jetbrains.annotations.Nullable)1