Search in sources :

Example 1 with PatchApplier

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

the class ConflictCreator method create.

public void create() throws PatchSyntaxException, IOException {
    // local changes, do not commit
    for (TreeConflictData.FileData data : myData.getLeftFiles()) {
        applyFileData(myMineDir, data);
    }
    final PatchReader reader = new PatchReader(myData.getTheirsPatch());
    final List<TextFilePatch> patches = reader.readTextPatches();
    final List<FilePatch> filePatchList = new ArrayList<>(patches);
    for (Iterator<FilePatch> iterator = filePatchList.iterator(); iterator.hasNext(); ) {
        final FilePatch patch = iterator.next();
        if (patch.isDeletedFile()) {
            myClientRunner.delete(myTheirsDir, patch.getBeforeName());
            iterator.remove();
        }
    }
    if (!filePatchList.isEmpty()) {
        PatchApplier<BinaryFilePatch> applier = new PatchApplier<>(myProject, myTheirsDir, filePatchList, (LocalChangeList) null, null, null);
        applier.setIgnoreContentRootsCheck();
        applier.execute();
        Assert.assertEquals(0, applier.getRemainingPatches().size());
    }
    TimeoutUtil.sleep(10);
    SvnVcs vcs = SvnVcs.getInstance(myProject);
    for (TextFilePatch patch : patches) {
        if (patch.isNewFile() || !Comparing.equal(patch.getAfterName(), patch.getBeforeName())) {
            final String afterName = patch.getAfterName();
            final String[] parts = afterName.split("/");
            String subPath = "";
            for (String part : parts) {
                final String path = subPath + part;
                Info info = vcs.getInfo(new File(myTheirsDir.getPath(), path));
                if (info == null || info.getURL() == null) {
                    myClientRunner.add(myTheirsDir, path);
                }
                subPath += part + "/";
            }
            if (!patch.isNewFile()) {
                myClientRunner.delete(myTheirsDir, patch.getBeforeName());
            }
        }
    }
    VfsUtilCore.visitChildrenRecursively(myTheirsDir, new VirtualFileVisitor() {

        @NotNull
        @Override
        public Result visitFileEx(@NotNull VirtualFile file) {
            if (!myTheirsDir.equals(file) && file.isDirectory() && file.getChildren().length == 0) {
                try {
                    myClientRunner.delete(myTheirsDir, file.getPath());
                } catch (IOException e) {
                    throw new VisitorException(e);
                }
            }
            return file.isDirectory() && SvnUtil.isAdminDirectory(file) ? SKIP_CHILDREN : CONTINUE;
        }
    }, IOException.class);
    // this will commit all patch changes
    myClientRunner.checkin(myTheirsDir);
    // this will create the conflict
    myClientRunner.update(myMineDir);
    myClientRunner.update(myTheirsDir);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Info(org.jetbrains.idea.svn.info.Info) VirtualFileVisitor(com.intellij.openapi.vfs.VirtualFileVisitor) NotNull(org.jetbrains.annotations.NotNull) PatchApplier(com.intellij.openapi.diff.impl.patch.formove.PatchApplier) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 2 with PatchApplier

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

the class ShelveChangesManager method unshelveChangeList.

@CalledInAny
public void unshelveChangeList(final ShelvedChangeList changeList, @Nullable final List<ShelvedChange> changes, @Nullable final List<ShelvedBinaryFile> binaryFiles, @Nullable final LocalChangeList targetChangeList, final boolean showSuccessNotification, final boolean systemOperation, final boolean reverse, final String leftConflictTitle, final String rightConflictTitle) {
    final List<FilePatch> remainingPatches = new ArrayList<>();
    final CommitContext commitContext = new CommitContext();
    final List<TextFilePatch> textFilePatches;
    try {
        textFilePatches = loadTextPatches(myProject, changeList, changes, remainingPatches, commitContext);
    } catch (IOException e) {
        LOG.info(e);
        PatchApplier.showError(myProject, "Cannot load patch(es): " + e.getMessage());
        return;
    } catch (PatchSyntaxException e) {
        PatchApplier.showError(myProject, "Cannot load patch(es): " + e.getMessage());
        LOG.info(e);
        return;
    }
    final List<FilePatch> patches = new ArrayList<>(textFilePatches);
    final List<ShelvedBinaryFile> remainingBinaries = new ArrayList<>();
    final List<ShelvedBinaryFile> binaryFilesToUnshelve = getBinaryFilesToUnshelve(changeList, binaryFiles, remainingBinaries);
    for (final ShelvedBinaryFile shelvedBinaryFile : binaryFilesToUnshelve) {
        patches.add(new ShelvedBinaryFilePatch(shelvedBinaryFile));
    }
    ApplicationManager.getApplication().invokeAndWait(() -> {
        final BinaryPatchApplier binaryPatchApplier = new BinaryPatchApplier();
        final PatchApplier<ShelvedBinaryFilePatch> patchApplier = new PatchApplier<>(myProject, myProject.getBaseDir(), patches, targetChangeList, binaryPatchApplier, commitContext, reverse, leftConflictTitle, rightConflictTitle);
        patchApplier.setIsSystemOperation(systemOperation);
        patchApplier.execute(showSuccessNotification, systemOperation);
        if (isRemoveFilesFromShelf() || systemOperation) {
            remainingPatches.addAll(patchApplier.getRemainingPatches());
            if (remainingPatches.isEmpty() && remainingBinaries.isEmpty()) {
                recycleChangeList(changeList);
            } else {
                saveRemainingPatches(changeList, remainingPatches, remainingBinaries, commitContext);
            }
        }
    });
}
Also used : IOException(java.io.IOException) CustomBinaryPatchApplier(com.intellij.openapi.diff.impl.patch.formove.CustomBinaryPatchApplier) PatchApplier(com.intellij.openapi.diff.impl.patch.formove.PatchApplier) CustomBinaryPatchApplier(com.intellij.openapi.diff.impl.patch.formove.CustomBinaryPatchApplier)

Example 3 with PatchApplier

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

the class RevertCommittedStuffAbstractAction method actionPerformed.

public void actionPerformed(final AnActionEvent e) {
    final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    final VirtualFile baseDir = project.getBaseDir();
    assert baseDir != null;
    final Change[] changes = myForPerformConvertor.convert(e);
    if (changes == null || changes.length == 0)
        return;
    final List<Change> changesList = new ArrayList<>();
    Collections.addAll(changesList, changes);
    FileDocumentManager.getInstance().saveAllDocuments();
    String defaultName = null;
    final ChangeList[] changeLists = e.getData(VcsDataKeys.CHANGE_LISTS);
    if (changeLists != null && changeLists.length > 0) {
        defaultName = VcsBundle.message("revert.changes.default.name", changeLists[0].getName());
    }
    final ChangeListChooser chooser = new ChangeListChooser(project, ChangeListManager.getInstance(project).getChangeListsCopy(), null, "Select Target Changelist", defaultName);
    if (!chooser.showAndGet()) {
        return;
    }
    final List<FilePatch> patches = new ArrayList<>();
    ProgressManager.getInstance().run(new Task.Backgroundable(project, VcsBundle.message("revert.changes.title"), true) {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            try {
                final List<Change> preprocessed = ChangesPreprocess.preprocessChangesRemoveDeletedForDuplicateMoved(changesList);
                patches.addAll(IdeaTextPatchBuilder.buildPatch(project, preprocessed, baseDir.getPresentableUrl(), true));
            } catch (final VcsException ex) {
                WaitForProgressToShow.runOrInvokeLaterAboveProgress(new Runnable() {

                    @Override
                    public void run() {
                        Messages.showErrorDialog(project, "Failed to revert changes: " + ex.getMessage(), VcsBundle.message("revert.changes.title"));
                    }
                }, null, myProject);
                indicator.cancel();
            }
        }

        @Override
        public void onSuccess() {
            new PatchApplier<BinaryFilePatch>(project, baseDir, patches, chooser.getSelectedList(), null, null).execute();
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Task(com.intellij.openapi.progress.Task) ChangeListChooser(com.intellij.openapi.vcs.changes.ui.ChangeListChooser) ArrayList(java.util.ArrayList) Change(com.intellij.openapi.vcs.changes.Change) BinaryFilePatch(com.intellij.openapi.diff.impl.patch.BinaryFilePatch) FilePatch(com.intellij.openapi.diff.impl.patch.FilePatch) Project(com.intellij.openapi.project.Project) ChangeList(com.intellij.openapi.vcs.changes.ChangeList) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsException(com.intellij.openapi.vcs.VcsException) PatchApplier(com.intellij.openapi.diff.impl.patch.formove.PatchApplier) ArrayList(java.util.ArrayList) List(java.util.List) ChangeList(com.intellij.openapi.vcs.changes.ChangeList)

Example 4 with PatchApplier

use of com.intellij.openapi.diff.impl.patch.formove.PatchApplier 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 5 with PatchApplier

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

the class ApplyPatchDefaultExecutor method apply.

@CalledInAwt
@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);
    executeAndApplyAdditionalInfo(localList, additionalInfo, commitContext, appliers);
}
Also used : PatchApplier(com.intellij.openapi.diff.impl.patch.formove.PatchApplier) CommitContext(com.intellij.openapi.vcs.changes.CommitContext) CalledInAwt(org.jetbrains.annotations.CalledInAwt)

Aggregations

PatchApplier (com.intellij.openapi.diff.impl.patch.formove.PatchApplier)5 CommitContext (com.intellij.openapi.vcs.changes.CommitContext)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ApplyPatchStatus (com.intellij.openapi.diff.impl.patch.ApplyPatchStatus)1 BinaryFilePatch (com.intellij.openapi.diff.impl.patch.BinaryFilePatch)1 FilePatch (com.intellij.openapi.diff.impl.patch.FilePatch)1 CustomBinaryPatchApplier (com.intellij.openapi.diff.impl.patch.formove.CustomBinaryPatchApplier)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 Project (com.intellij.openapi.project.Project)1 VcsException (com.intellij.openapi.vcs.VcsException)1 Change (com.intellij.openapi.vcs.changes.Change)1 ChangeList (com.intellij.openapi.vcs.changes.ChangeList)1 ChangeListChooser (com.intellij.openapi.vcs.changes.ui.ChangeListChooser)1 VirtualFileVisitor (com.intellij.openapi.vfs.VirtualFileVisitor)1 File (java.io.File)1 List (java.util.List)1 CalledInAwt (org.jetbrains.annotations.CalledInAwt)1