Search in sources :

Example 1 with FilePatch

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

the class ApplyPatchSaveToFileExecutor method savePatch.

private void savePatch(@NotNull MultiMap<VirtualFile, TextFilePatchInProgress> patchGroups, @NotNull VirtualFileWrapper targetFile) {
    VirtualFile newPatchBase = notNull(myNewPatchBase, myProject.getBaseDir());
    try {
        List<FilePatch> textPatches = toOnePatchGroup(patchGroups, newPatchBase);
        PatchWriter.writePatches(myProject, targetFile.getFile().getPath(), newPatchBase.getPath(), textPatches, new CommitContext(), CharsetToolkit.UTF8_CHARSET);
    } catch (IOException e) {
        LOG.info(e);
        WaitForProgressToShow.runOrInvokeLaterAboveProgress(() -> Messages.showErrorDialog(myProject, message("create.patch.error.title", e.getMessage()), getErrorTitle()), null, myProject);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CommitContext(com.intellij.openapi.vcs.changes.CommitContext) IOException(java.io.IOException) TextFilePatch(com.intellij.openapi.diff.impl.patch.TextFilePatch) FilePatch(com.intellij.openapi.diff.impl.patch.FilePatch)

Example 2 with FilePatch

use of com.intellij.openapi.diff.impl.patch.FilePatch 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 3 with FilePatch

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

the class PatchingTestCase method applyPatch.

protected void applyPatch() throws Exception {
    PatchReader reader = PatchVirtualFileReader.create(LocalFileSystem.getInstance().refreshAndFindFileByPath(patchFilePath));
    List<FilePatch> patches = new ArrayList<>(reader.readTextPatches());
    new PatchApplier<BinaryFilePatch>(myProject, myRoot, patches, null, null, null).execute();
}
Also used : ArrayList(java.util.ArrayList) FilePatch(com.intellij.openapi.diff.impl.patch.FilePatch) BinaryFilePatch(com.intellij.openapi.diff.impl.patch.BinaryFilePatch) BinaryFilePatch(com.intellij.openapi.diff.impl.patch.BinaryFilePatch) PatchReader(com.intellij.openapi.diff.impl.patch.PatchReader)

Example 4 with FilePatch

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

the class PathsVerifier method nonWriteActionPreCheck.

@CalledInAwt
public List<FilePatch> nonWriteActionPreCheck() {
    List<FilePatch> failedToApply = ContainerUtil.newArrayList();
    myDelayedPrecheckContext = new DelayedPrecheckContext(myProject);
    for (FilePatch patch : myPatches) {
        final CheckPath checker = getChecker(patch);
        if (!checker.canBeApplied(myDelayedPrecheckContext)) {
            revert(checker.getErrorMessage());
            failedToApply.add(patch);
        }
    }
    final Collection<FilePatch> skipped = myDelayedPrecheckContext.doDelayed();
    mySkipped.addAll(skipped);
    myPatches.removeAll(skipped);
    myPatches.removeAll(failedToApply);
    return failedToApply;
}
Also used : ShelvedBinaryFilePatch(com.intellij.openapi.vcs.changes.shelf.ShelvedBinaryFilePatch) BinaryFilePatch(com.intellij.openapi.diff.impl.patch.BinaryFilePatch) ApplyTextFilePatch(com.intellij.openapi.diff.impl.patch.apply.ApplyTextFilePatch) TextFilePatch(com.intellij.openapi.diff.impl.patch.TextFilePatch) FilePatch(com.intellij.openapi.diff.impl.patch.FilePatch) CalledInAwt(org.jetbrains.annotations.CalledInAwt)

Example 5 with FilePatch

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

the class PathsVerifier method execute.

public List<FilePatch> execute() {
    List<FilePatch> failedPatches = ContainerUtil.newArrayList();
    try {
        final List<CheckPath> checkers = new ArrayList<CheckPath>(myPatches.size());
        for (FilePatch patch : myPatches) {
            final CheckPath checker = getChecker(patch);
            checkers.add(checker);
        }
        for (CheckPath checker : checkers) {
            if (!checker.check()) {
                failedPatches.add(checker.getPatch());
                revert(checker.getErrorMessage());
            }
        }
    } catch (IOException e) {
        revert(e.getMessage());
    }
    myPatches.removeAll(failedPatches);
    return failedPatches;
}
Also used : IOException(java.io.IOException) ShelvedBinaryFilePatch(com.intellij.openapi.vcs.changes.shelf.ShelvedBinaryFilePatch) BinaryFilePatch(com.intellij.openapi.diff.impl.patch.BinaryFilePatch) ApplyTextFilePatch(com.intellij.openapi.diff.impl.patch.apply.ApplyTextFilePatch) TextFilePatch(com.intellij.openapi.diff.impl.patch.TextFilePatch) FilePatch(com.intellij.openapi.diff.impl.patch.FilePatch)

Aggregations

FilePatch (com.intellij.openapi.diff.impl.patch.FilePatch)13 TextFilePatch (com.intellij.openapi.diff.impl.patch.TextFilePatch)8 BinaryFilePatch (com.intellij.openapi.diff.impl.patch.BinaryFilePatch)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 ShelvedBinaryFilePatch (com.intellij.openapi.vcs.changes.shelf.ShelvedBinaryFilePatch)4 IOException (java.io.IOException)4 ApplyTextFilePatch (com.intellij.openapi.diff.impl.patch.apply.ApplyTextFilePatch)3 ArrayList (java.util.ArrayList)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 VcsException (com.intellij.openapi.vcs.VcsException)2 MultiMap (com.intellij.util.containers.MultiMap)2 File (java.io.File)2 NotNull (org.jetbrains.annotations.NotNull)2 DiffRequestProducer (com.intellij.diff.chains.DiffRequestProducer)1 UnknownFileTypeDiffRequest (com.intellij.diff.requests.UnknownFileTypeDiffRequest)1 ApplyPatchContext (com.intellij.openapi.diff.impl.patch.ApplyPatchContext)1 ApplyPatchStatus (com.intellij.openapi.diff.impl.patch.ApplyPatchStatus)1 BinaryEncoder (com.intellij.openapi.diff.impl.patch.BinaryEncoder)1 PatchEP (com.intellij.openapi.diff.impl.patch.PatchEP)1 PatchReader (com.intellij.openapi.diff.impl.patch.PatchReader)1