From b69fdd879b1bf83b2cbdad30db5b040cc07529de Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Thu, 14 Jan 2016 19:17:21 +0300 Subject: [PATCH] [patch]: implement best attempt to apply patch (IDEA-148799, IDEA-60470, IDEA-35927, IDEA-148175) * move rollback patch applying under modal progress; * do not delete applied files from shelveList if failed or aborted; --- .../diff/impl/patch/formove/UndoApplyPatchDialog.java | 8 +++++++- .../vcs/changes/patch/ApplyPatchDefaultExecutor.java | 11 +++++++---- .../changes/patch/UnshelvePatchDefaultExecutor.java | 7 +++++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/UndoApplyPatchDialog.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/UndoApplyPatchDialog.java index 1306c7c5bc63..5c1bfe5cfc2d 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/UndoApplyPatchDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/UndoApplyPatchDialog.java @@ -17,6 +17,7 @@ package com.intellij.openapi.diff.impl.patch.formove; import com.intellij.history.Label; import com.intellij.history.LocalHistory; +import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.util.text.StringUtil; @@ -71,7 +72,12 @@ class UndoApplyPatchDialog extends DialogWrapper { @Override protected void doOKAction() { super.doOKAction(); - LocalHistory.getInstance().revertToLabel(myProject, myProject.getBaseDir(), myBeforeLabel); + ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() { + @Override + public void run() { + LocalHistory.getInstance().revertToLabel(myProject, myProject.getBaseDir(), myBeforeLabel); + } + }, "Rollback Applied Changes...", true, myProject); } static void rollbackApplyPatch(@NotNull Project project, @NotNull List filePaths, diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchDefaultExecutor.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchDefaultExecutor.java index 69bbad358a5d..1a8aa5c86293 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchDefaultExecutor.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchDefaultExecutor.java @@ -64,12 +64,15 @@ public class ApplyPatchDefaultExecutor implements ApplyPatchExecutor>, PatchSyntaxException> additionalInfo, - @NotNull CommitContext commitContext, @NotNull Collection appliers) { - if (PatchApplier.executePatchGroup(appliers, localList) != ApplyPatchStatus.ABORT) { + protected ApplyPatchStatus executeAndApplyAdditionalInfo(@Nullable LocalChangeList localList, + @Nullable TransparentlyFailedValueI>, PatchSyntaxException> additionalInfo, + @NotNull CommitContext commitContext, + @NotNull Collection appliers) { + final ApplyPatchStatus applyPatchStatus = PatchApplier.executePatchGroup(appliers, localList); + if (applyPatchStatus != ApplyPatchStatus.ABORT) { applyAdditionalInfo(myProject, additionalInfo, commitContext); } + return applyPatchStatus; } @NotNull diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/UnshelvePatchDefaultExecutor.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/UnshelvePatchDefaultExecutor.java index 157dce2ff02c..3c4f0ba453ad 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/UnshelvePatchDefaultExecutor.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/UnshelvePatchDefaultExecutor.java @@ -16,6 +16,7 @@ package com.intellij.openapi.vcs.changes.patch; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.diff.impl.patch.ApplyPatchStatus; import com.intellij.openapi.diff.impl.patch.FilePatch; import com.intellij.openapi.diff.impl.patch.PatchSyntaxException; import com.intellij.openapi.diff.impl.patch.formove.PatchApplier; @@ -60,8 +61,10 @@ public class UnshelvePatchDefaultExecutor extends ApplyPatchDefaultExecutor { final CommitContext commitContext = new CommitContext(); applyAdditionalInfoBefore(myProject, additionalInfo, commitContext); final Collection appliers = getPatchAppliers(patchGroups, localList, commitContext); - executeAndApplyAdditionalInfo(localList, additionalInfo, commitContext, appliers); - removeAppliedAndSaveRemainedIfNeeded(appliers, commitContext); + final ApplyPatchStatus patchStatus = executeAndApplyAdditionalInfo(localList, additionalInfo, commitContext, appliers); + if (patchStatus != ApplyPatchStatus.ABORT && patchStatus != ApplyPatchStatus.FAILURE) { + removeAppliedAndSaveRemainedIfNeeded(appliers, commitContext); // remove only if partly applied or successful + } } private void removeAppliedAndSaveRemainedIfNeeded(@NotNull Collection appliers, @NotNull CommitContext commitContext) {