Search in sources :

Example 1 with CommitContext

use of com.intellij.openapi.vcs.changes.CommitContext 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 CommitContext

use of com.intellij.openapi.vcs.changes.CommitContext in project intellij-community by JetBrains.

the class DiffShelvedChangesAction method processTextChanges.

private static void processTextChanges(@NotNull final Project project, @NotNull List<ShelvedChange> changesFromFirstList, @NotNull List<MyDiffRequestProducer> diffRequestProducers) {
    final String base = project.getBasePath();
    final ApplyPatchContext patchContext = new ApplyPatchContext(project.getBaseDir(), 0, false, false);
    final PatchesPreloader preloader = new PatchesPreloader(project);
    for (final ShelvedChange shelvedChange : changesFromFirstList) {
        final String beforePath = shelvedChange.getBeforePath();
        final String afterPath = shelvedChange.getAfterPath();
        final FilePath filePath = VcsUtil.getFilePath(new File(base, afterPath == null ? beforePath : afterPath));
        final boolean isNewFile = FileStatus.ADDED.equals(shelvedChange.getFileStatus());
        // isNewFile -> parent directory, !isNewFile -> file
        final VirtualFile file;
        try {
            file = ApplyFilePatchBase.findPatchTarget(patchContext, beforePath, afterPath, isNewFile);
            if (!isNewFile && (file == null || !file.exists()))
                throw new FileNotFoundException(beforePath);
        } catch (IOException e) {
            diffRequestProducers.add(new MyDiffRequestProducer(shelvedChange, filePath) {

                @NotNull
                @Override
                public DiffRequest process(@NotNull UserDataHolder context, @NotNull ProgressIndicator indicator) throws DiffRequestProducerException, ProcessCanceledException {
                    throw new DiffRequestProducerException("Cannot find base for '" + (beforePath != null ? beforePath : afterPath) + "'");
                }
            });
            continue;
        }
        diffRequestProducers.add(new MyDiffRequestProducer(shelvedChange, filePath) {

            @NotNull
            @Override
            public DiffRequest process(@NotNull UserDataHolder context, @NotNull ProgressIndicator indicator) throws DiffRequestProducerException, ProcessCanceledException {
                if (!isNewFile && file.getFileType() == UnknownFileType.INSTANCE) {
                    return new UnknownFileTypeDiffRequest(file, getName());
                }
                if (shelvedChange.isConflictingChange(project)) {
                    try {
                        final CommitContext commitContext = new CommitContext();
                        final TextFilePatch patch = preloader.getPatch(shelvedChange, commitContext);
                        final FilePath pathBeforeRename = patchContext.getPathBeforeRename(file);
                        final String relativePath = patch.getAfterName() == null ? patch.getBeforeName() : patch.getAfterName();
                        final Getter<CharSequence> baseContentGetter = new Getter<CharSequence>() {

                            @Override
                            public CharSequence get() {
                                BaseRevisionTextPatchEP baseRevisionTextPatchEP = Extensions.findExtension(PatchEP.EP_NAME, project, BaseRevisionTextPatchEP.class);
                                return baseRevisionTextPatchEP.provideContent(relativePath, commitContext);
                            }
                        };
                        Getter<ApplyPatchForBaseRevisionTexts> getter = new Getter<ApplyPatchForBaseRevisionTexts>() {

                            @Override
                            public ApplyPatchForBaseRevisionTexts get() {
                                return ApplyPatchForBaseRevisionTexts.create(project, file, pathBeforeRename, patch, baseContentGetter);
                            }
                        };
                        return PatchDiffRequestFactory.createConflictDiffRequest(project, file, patch, "Shelved Version", getter, getName(), context, indicator);
                    } catch (VcsException e) {
                        throw new DiffRequestProducerException("Can't show diff for '" + getName() + "'", e);
                    }
                } else {
                    final Change change = shelvedChange.getChange(project);
                    return PatchDiffRequestFactory.createDiffRequest(project, change, getName(), context, indicator);
                }
            }
        });
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Getter(com.intellij.openapi.util.Getter) FileNotFoundException(java.io.FileNotFoundException) DiffRequest(com.intellij.diff.requests.DiffRequest) UnknownFileTypeDiffRequest(com.intellij.diff.requests.UnknownFileTypeDiffRequest) UnknownFileTypeDiffRequest(com.intellij.diff.requests.UnknownFileTypeDiffRequest) NotNull(org.jetbrains.annotations.NotNull) UserDataHolder(com.intellij.openapi.util.UserDataHolder) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) CommitContext(com.intellij.openapi.vcs.changes.CommitContext) ApplyPatchForBaseRevisionTexts(com.intellij.openapi.vcs.changes.patch.ApplyPatchForBaseRevisionTexts) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) FilePath(com.intellij.openapi.vcs.FilePath) DiffRequestProducerException(com.intellij.diff.chains.DiffRequestProducerException) IOException(java.io.IOException) Change(com.intellij.openapi.vcs.changes.Change) VcsException(com.intellij.openapi.vcs.VcsException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 3 with CommitContext

use of com.intellij.openapi.vcs.changes.CommitContext 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 CommitContext

use of com.intellij.openapi.vcs.changes.CommitContext 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

CommitContext (com.intellij.openapi.vcs.changes.CommitContext)4 PatchApplier (com.intellij.openapi.diff.impl.patch.formove.PatchApplier)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 IOException (java.io.IOException)2 DiffRequestProducerException (com.intellij.diff.chains.DiffRequestProducerException)1 DiffRequest (com.intellij.diff.requests.DiffRequest)1 UnknownFileTypeDiffRequest (com.intellij.diff.requests.UnknownFileTypeDiffRequest)1 ApplyPatchStatus (com.intellij.openapi.diff.impl.patch.ApplyPatchStatus)1 FilePatch (com.intellij.openapi.diff.impl.patch.FilePatch)1 TextFilePatch (com.intellij.openapi.diff.impl.patch.TextFilePatch)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Getter (com.intellij.openapi.util.Getter)1 UserDataHolder (com.intellij.openapi.util.UserDataHolder)1 FilePath (com.intellij.openapi.vcs.FilePath)1 VcsException (com.intellij.openapi.vcs.VcsException)1 Change (com.intellij.openapi.vcs.changes.Change)1 ApplyPatchForBaseRevisionTexts (com.intellij.openapi.vcs.changes.patch.ApplyPatchForBaseRevisionTexts)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1