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);
}
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);
}
}
});
}
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();
}
});
}
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);
}
}
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);
}
Aggregations