[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;
This commit is contained in:
Nadya Zabrodina
2016-01-25 17:05:17 +03:00
parent 4fcd0f9d62
commit b69fdd879b
3 changed files with 19 additions and 7 deletions
@@ -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<FilePath> filePaths,
@@ -64,12 +64,15 @@ public class ApplyPatchDefaultExecutor implements ApplyPatchExecutor<AbstractFil
executeAndApplyAdditionalInfo(localList, additionalInfo, commitContext, appliers);
}
protected void executeAndApplyAdditionalInfo(@Nullable LocalChangeList localList,
@Nullable TransparentlyFailedValueI<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo,
@NotNull CommitContext commitContext, @NotNull Collection<PatchApplier> appliers) {
if (PatchApplier.executePatchGroup(appliers, localList) != ApplyPatchStatus.ABORT) {
protected ApplyPatchStatus executeAndApplyAdditionalInfo(@Nullable LocalChangeList localList,
@Nullable TransparentlyFailedValueI<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo,
@NotNull CommitContext commitContext,
@NotNull Collection<PatchApplier> appliers) {
final ApplyPatchStatus applyPatchStatus = PatchApplier.executePatchGroup(appliers, localList);
if (applyPatchStatus != ApplyPatchStatus.ABORT) {
applyAdditionalInfo(myProject, additionalInfo, commitContext);
}
return applyPatchStatus;
}
@NotNull
@@ -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<PatchApplier> 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<PatchApplier> appliers, @NotNull CommitContext commitContext) {