mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-83610 Subversion: revert file rename from Repositories view causes errors
This commit is contained in:
+38
-8
@@ -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<AnActionEvent, Change[]> myForUpdateConvertor;
|
||||
private final Convertor<AnActionEvent, Change[]> myForPerformConvertor;
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vcs.changes.actions.RevertCommittedStuffAbstractAction");
|
||||
|
||||
public RevertCommittedStuffAbstractAction(final Convertor<AnActionEvent, Change[]> forUpdateConvertor,
|
||||
final Convertor<AnActionEvent, Change[]> forPerformConvertor) {
|
||||
@@ -63,6 +62,7 @@ abstract class RevertCommittedStuffAbstractAction extends AnAction implements Du
|
||||
if (changes == null || changes.length == 0) return;
|
||||
final List<Change> changesList = new ArrayList<Change>();
|
||||
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<Change> 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<Change> preprocessChanges(List<Change> list) {
|
||||
final List<Change> result = new ArrayList<Change>();
|
||||
final Map<FilePath, Change> map = new HashMap<FilePath, Change>();
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user