Search in sources :

Example 1 with ApplyPatchStatus

use of com.intellij.openapi.diff.impl.patch.ApplyPatchStatus in project intellij-community by JetBrains.

the class PatchApplier method executePatchGroup.

@CalledInAwt
public static ApplyPatchStatus executePatchGroup(final Collection<PatchApplier> group, final LocalChangeList localChangeList) {
    //?
    if (group.isEmpty())
        return ApplyPatchStatus.SUCCESS;
    final Project project = group.iterator().next().myProject;
    ApplyPatchStatus result = ApplyPatchStatus.SUCCESS;
    for (PatchApplier patchApplier : group) {
        result = ApplyPatchStatus.and(result, patchApplier.nonWriteActionPreCheck());
    }
    final Label beforeLabel = LocalHistory.getInstance().putSystemLabel(project, "Before patch");
    final TriggerAdditionOrDeletion trigger = new TriggerAdditionOrDeletion(project);
    final Ref<ApplyPatchStatus> refStatus = new Ref<>(result);
    try {
        CommandProcessor.getInstance().executeCommand(project, new Runnable() {

            @Override
            public void run() {
                for (PatchApplier applier : group) {
                    refStatus.set(ApplyPatchStatus.and(refStatus.get(), applier.createFiles()));
                    applier.addSkippedItems(trigger);
                }
                trigger.prepare();
                if (refStatus.get() == ApplyPatchStatus.SUCCESS) {
                    // all pre-check results are valuable only if not successful; actual status we can receive after executeWritable
                    refStatus.set(null);
                }
                for (PatchApplier applier : group) {
                    refStatus.set(ApplyPatchStatus.and(refStatus.get(), applier.executeWritable()));
                    if (refStatus.get() == ApplyPatchStatus.ABORT)
                        break;
                }
            }
        }, VcsBundle.message("patch.apply.command"), null);
    } finally {
        VcsFileListenerContextHelper.getInstance(project).clearContext();
        LocalHistory.getInstance().putSystemLabel(project, "After patch");
    }
    result = refStatus.get();
    result = result == null ? ApplyPatchStatus.FAILURE : result;
    trigger.processIt();
    final Set<FilePath> directlyAffected = new HashSet<>();
    final Set<VirtualFile> indirectlyAffected = new HashSet<>();
    for (PatchApplier applier : group) {
        directlyAffected.addAll(applier.getDirectlyAffected());
        indirectlyAffected.addAll(applier.getIndirectlyAffected());
    }
    directlyAffected.addAll(trigger.getAffected());
    final Consumer<Collection<FilePath>> mover = localChangeList == null ? null : createMover(project, localChangeList);
    refreshPassedFilesAndMoveToChangelist(project, directlyAffected, indirectlyAffected, mover);
    if (result == ApplyPatchStatus.FAILURE) {
        suggestRollback(project, group, beforeLabel);
    } else if (result == ApplyPatchStatus.ABORT) {
        rollbackUnderProgress(project, project.getBaseDir(), beforeLabel);
    }
    showApplyStatus(project, result);
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ApplyPatchStatus(com.intellij.openapi.diff.impl.patch.ApplyPatchStatus) Label(com.intellij.history.Label) Project(com.intellij.openapi.project.Project) Ref(com.intellij.openapi.util.Ref) CalledInAwt(org.jetbrains.annotations.CalledInAwt)

Example 2 with ApplyPatchStatus

use of com.intellij.openapi.diff.impl.patch.ApplyPatchStatus in project intellij-community by JetBrains.

the class PatchApplier method executeWritable.

@Nullable
protected ApplyPatchStatus executeWritable() {
    final ReadonlyStatusHandler.OperationStatus readOnlyFilesStatus = getReadOnlyFilesStatus(myVerifier.getWritableFiles());
    if (readOnlyFilesStatus.hasReadonlyFiles()) {
        showError(myProject, readOnlyFilesStatus.getReadonlyFilesMessage());
        return ApplyPatchStatus.ABORT;
    }
    myFailedPatches.addAll(myVerifier.filterBadFileTypePatches());
    ApplyPatchStatus result = myFailedPatches.isEmpty() ? null : ApplyPatchStatus.FAILURE;
    final List<Pair<VirtualFile, ApplyTextFilePatch>> textPatches = myVerifier.getTextPatches();
    try {
        markInternalOperation(textPatches, true);
        return ApplyPatchStatus.and(result, actualApply(textPatches, myVerifier.getBinaryPatches(), myCommitContext));
    } finally {
        markInternalOperation(textPatches, false);
    }
}
Also used : ApplyPatchStatus(com.intellij.openapi.diff.impl.patch.ApplyPatchStatus) ReadonlyStatusHandler(com.intellij.openapi.vfs.ReadonlyStatusHandler) Pair(com.intellij.openapi.util.Pair) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with ApplyPatchStatus

use of com.intellij.openapi.diff.impl.patch.ApplyPatchStatus in project intellij-community by JetBrains.

the class UnshelvePatchDefaultExecutor method apply.

@Override
public void apply(@NotNull List<FilePatch> remaining, @NotNull MultiMap<VirtualFile, AbstractFilePatchInProgress> patchGroupsToApply, @Nullable LocalChangeList localList, @Nullable String fileName, @Nullable ThrowableComputable<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo) {
    final CommitContext commitContext = new CommitContext();
    applyAdditionalInfoBefore(myProject, additionalInfo, commitContext);
    final Collection<PatchApplier> appliers = getPatchAppliers(patchGroupsToApply, localList, commitContext);
    final ApplyPatchStatus patchStatus = executeAndApplyAdditionalInfo(localList, additionalInfo, commitContext, appliers);
    if (patchStatus != ApplyPatchStatus.ABORT && patchStatus != ApplyPatchStatus.FAILURE) {
        // remove only if partly applied or successful
        removeAppliedAndSaveRemainedIfNeeded(remaining, appliers, commitContext);
    }
}
Also used : PatchApplier(com.intellij.openapi.diff.impl.patch.formove.PatchApplier) ApplyPatchStatus(com.intellij.openapi.diff.impl.patch.ApplyPatchStatus) CommitContext(com.intellij.openapi.vcs.changes.CommitContext)

Example 4 with ApplyPatchStatus

use of com.intellij.openapi.diff.impl.patch.ApplyPatchStatus in project intellij-community by JetBrains.

the class PatchApplier method actualApply.

@Nullable
private ApplyPatchStatus actualApply(final List<Pair<VirtualFile, ApplyTextFilePatch>> textPatches, final List<Pair<VirtualFile, ApplyFilePatchBase<BinaryType>>> binaryPatches, final CommitContext commitContext) {
    final ApplyPatchContext context = new ApplyPatchContext(myBaseDirectory, 0, true, true);
    ApplyPatchStatus status;
    try {
        status = applyList(textPatches, context, null, commitContext);
        if (status == ApplyPatchStatus.ABORT)
            return status;
        if (myCustomForBinaries == null) {
            status = applyList(binaryPatches, context, status, commitContext);
        } else {
            ApplyPatchStatus patchStatus = myCustomForBinaries.apply(binaryPatches);
            final List<FilePatch> appliedPatches = myCustomForBinaries.getAppliedPatches();
            moveForCustomBinaries(binaryPatches, appliedPatches);
            status = ApplyPatchStatus.and(status, patchStatus);
            myRemainingPatches.removeAll(appliedPatches);
        }
    } catch (IOException e) {
        showError(myProject, e.getMessage());
        return ApplyPatchStatus.ABORT;
    }
    return status;
}
Also used : ApplyPatchContext(com.intellij.openapi.diff.impl.patch.ApplyPatchContext) ApplyPatchStatus(com.intellij.openapi.diff.impl.patch.ApplyPatchStatus) IOException(java.io.IOException) ApplyTextFilePatch(com.intellij.openapi.diff.impl.patch.apply.ApplyTextFilePatch) FilePatch(com.intellij.openapi.diff.impl.patch.FilePatch) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with ApplyPatchStatus

use of com.intellij.openapi.diff.impl.patch.ApplyPatchStatus in project intellij-community by JetBrains.

the class PatchApplier method applyList.

private <V extends FilePatch, T extends ApplyFilePatchBase<V>> ApplyPatchStatus applyList(final List<Pair<VirtualFile, T>> patches, final ApplyPatchContext context, ApplyPatchStatus status, CommitContext commiContext) throws IOException {
    for (Pair<VirtualFile, T> patch : patches) {
        ApplyPatchStatus patchStatus = ApplyPatchAction.applyOnly(myProject, patch.getSecond(), context, patch.getFirst(), commiContext, myReverseConflict, myLeftConflictPanelTitle, myRightConflictPanelTitle);
        if (patchStatus == ApplyPatchStatus.ABORT)
            return patchStatus;
        status = ApplyPatchStatus.and(status, patchStatus);
        if (patchStatus == ApplyPatchStatus.FAILURE) {
            myFailedPatches.add(patch.getSecond().getPatch());
            continue;
        }
        if (patchStatus != ApplyPatchStatus.SKIP) {
            myVerifier.doMoveIfNeeded(patch.getFirst());
            myRemainingPatches.remove(patch.getSecond().getPatch());
        }
    }
    return status;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ApplyPatchStatus(com.intellij.openapi.diff.impl.patch.ApplyPatchStatus)

Aggregations

ApplyPatchStatus (com.intellij.openapi.diff.impl.patch.ApplyPatchStatus)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Nullable (org.jetbrains.annotations.Nullable)2 Label (com.intellij.history.Label)1 ApplyPatchContext (com.intellij.openapi.diff.impl.patch.ApplyPatchContext)1 FilePatch (com.intellij.openapi.diff.impl.patch.FilePatch)1 ApplyTextFilePatch (com.intellij.openapi.diff.impl.patch.apply.ApplyTextFilePatch)1 PatchApplier (com.intellij.openapi.diff.impl.patch.formove.PatchApplier)1 Project (com.intellij.openapi.project.Project)1 Pair (com.intellij.openapi.util.Pair)1 Ref (com.intellij.openapi.util.Ref)1 CommitContext (com.intellij.openapi.vcs.changes.CommitContext)1 ReadonlyStatusHandler (com.intellij.openapi.vfs.ReadonlyStatusHandler)1 IOException (java.io.IOException)1 CalledInAwt (org.jetbrains.annotations.CalledInAwt)1