Search in sources :

Example 11 with FilePatch

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

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

the class ShelvedChangeList method getChanges.

public List<ShelvedChange> getChanges(Project project) {
    if (myChanges == null) {
        try {
            myChanges = new ArrayList<>();
            final List<? extends FilePatch> list = ShelveChangesManager.loadPatchesWithoutContent(project, PATH, null);
            for (FilePatch patch : list) {
                FileStatus status;
                if (patch.isNewFile()) {
                    status = FileStatus.ADDED;
                } else if (patch.isDeletedFile()) {
                    status = FileStatus.DELETED;
                } else {
                    status = FileStatus.MODIFIED;
                }
                myChanges.add(new ShelvedChange(PATH, patch.getBeforeName(), patch.getAfterName(), status));
            }
        } catch (Exception e) {
            LOG.error("Failed to parse the file patch: [" + PATH + "]", e);
        }
    }
    return myChanges;
}
Also used : FileStatus(com.intellij.openapi.vcs.FileStatus) FilePatch(com.intellij.openapi.diff.impl.patch.FilePatch) InvalidDataException(com.intellij.openapi.util.InvalidDataException) WriteExternalException(com.intellij.openapi.util.WriteExternalException)

Example 13 with FilePatch

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

the class ApplyPatchSaveToFileExecutor method toOnePatchGroup.

@NotNull
public static List<FilePatch> toOnePatchGroup(@NotNull MultiMap<VirtualFile, TextFilePatchInProgress> patchGroups, @NotNull VirtualFile newPatchBase) throws IOException {
    List<FilePatch> result = newArrayList();
    for (Map.Entry<VirtualFile, Collection<TextFilePatchInProgress>> entry : patchGroups.entrySet()) {
        VirtualFile oldPatchBase = entry.getKey();
        String relativePath = VfsUtilCore.getRelativePath(oldPatchBase, newPatchBase, '/');
        boolean toConvert = !isEmptyOrSpaces(relativePath) && !".".equals(relativePath);
        for (TextFilePatchInProgress patchInProgress : entry.getValue()) {
            TextFilePatch patch = patchInProgress.getPatch();
            if (toConvert) {
                patch.setBeforeName(getNewBaseRelativePath(newPatchBase, oldPatchBase, patch.getBeforeName()));
                patch.setAfterName(getNewBaseRelativePath(newPatchBase, oldPatchBase, patch.getAfterName()));
            }
            result.add(patch);
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TextFilePatchInProgress(com.intellij.openapi.vcs.changes.patch.TextFilePatchInProgress) Collection(java.util.Collection) TextFilePatch(com.intellij.openapi.diff.impl.patch.TextFilePatch) FilePatch(com.intellij.openapi.diff.impl.patch.FilePatch) Map(java.util.Map) MultiMap(com.intellij.util.containers.MultiMap) TextFilePatch(com.intellij.openapi.diff.impl.patch.TextFilePatch) NotNull(org.jetbrains.annotations.NotNull)

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