From b53f372dfafe6b075a1bd2ca549cb5df2ea29328 Mon Sep 17 00:00:00 2001 From: irengrig Date: Wed, 28 Mar 2012 16:03:23 +0400 Subject: [PATCH] IDEA-83610 Subversion: revert file rename from Repositories view causes errors --- .../RevertCommittedStuffAbstractAction.java | 46 +++++++++++++++---- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/RevertCommittedStuffAbstractAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/RevertCommittedStuffAbstractAction.java index 42b5a2838876..ad2fe9aeacaa 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/RevertCommittedStuffAbstractAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/RevertCommittedStuffAbstractAction.java @@ -18,36 +18,35 @@ package com.intellij.openapi.vcs.changes.actions; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.PlatformDataKeys; +import com.intellij.openapi.diagnostic.rt.Logger; import com.intellij.openapi.diff.impl.patch.BinaryFilePatch; import com.intellij.openapi.diff.impl.patch.FilePatch; import com.intellij.openapi.diff.impl.patch.IdeaTextPatchBuilder; import com.intellij.openapi.diff.impl.patch.formove.PatchApplier; +import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.VcsBundle; import com.intellij.openapi.vcs.VcsDataKeys; import com.intellij.openapi.vcs.VcsException; -import com.intellij.openapi.vcs.changes.BackgroundFromStartOption; -import com.intellij.openapi.vcs.changes.Change; -import com.intellij.openapi.vcs.changes.ChangeList; -import com.intellij.openapi.vcs.changes.ChangeListManager; +import com.intellij.openapi.vcs.changes.*; import com.intellij.openapi.vcs.changes.ui.ChangeListChooser; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.WaitForProgressToShow; import com.intellij.util.containers.Convertor; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import java.util.*; abstract class RevertCommittedStuffAbstractAction extends AnAction implements DumbAware { private final Convertor myForUpdateConvertor; private final Convertor myForPerformConvertor; + private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vcs.changes.actions.RevertCommittedStuffAbstractAction"); public RevertCommittedStuffAbstractAction(final Convertor forUpdateConvertor, final Convertor forPerformConvertor) { @@ -63,6 +62,7 @@ abstract class RevertCommittedStuffAbstractAction extends AnAction implements Du if (changes == null || changes.length == 0) return; final List changesList = new ArrayList(); Collections.addAll(changesList, changes); + FileDocumentManager.getInstance().saveAllDocuments(); String defaultName = null; final ChangeList[] changeLists = e.getData(VcsDataKeys.CHANGE_LISTS); @@ -81,7 +81,8 @@ abstract class RevertCommittedStuffAbstractAction extends AnAction implements Du @Override public void run(@NotNull ProgressIndicator indicator) { try { - patches.addAll(IdeaTextPatchBuilder.buildPatch(project, changesList, baseDir.getPresentableUrl(), true)); + final List preprocessed = preprocessChanges(changesList); + patches.addAll(IdeaTextPatchBuilder.buildPatch(project, preprocessed, baseDir.getPresentableUrl(), true)); } catch (final VcsException ex) { WaitForProgressToShow.runOrInvokeLaterAboveProgress(new Runnable() { @@ -101,6 +102,35 @@ abstract class RevertCommittedStuffAbstractAction extends AnAction implements Du }); } + private List preprocessChanges(List list) { + final List result = new ArrayList(); + final Map map = new HashMap(); + for (Change change : list) { + if (change.getBeforeRevision() == null) { + result.add(change); + } else { + final FilePath beforePath = ChangesUtil.getBeforePath(change); + final Change existing = map.get(beforePath); + if (existing == null) { + map.put(beforePath, change); + continue; + } + if (change.getAfterRevision() == null && existing.getAfterRevision() == null) continue; + if (change.getAfterRevision() != null && existing.getAfterRevision() != null) { + LOG.error("Incorrect changes list: " + list); + } + if (existing.getAfterRevision() != null && change.getAfterRevision() == null) { + continue; // skip delete change + } + if (change.getAfterRevision() != null && existing.getAfterRevision() == null) { + map.put(beforePath, change); // skip delete change + } + } + } + result.addAll(map.values()); + return result; + } + public void update(final AnActionEvent e) { final Project project = e.getData(PlatformDataKeys.PROJECT); final Change[] changes = myForUpdateConvertor.convert(e);