use of com.intellij.diff.merge.MergeRequest in project intellij-community by JetBrains.
the class MergeFilesAction method actionPerformed.
public void actionPerformed(AnActionEvent e) {
DataContext context = e.getDataContext();
VirtualFile[] files = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(context);
if (files == null || files.length != 3) {
return;
}
DiffRequestFactory diffRequestFactory = DiffRequestFactory.getInstance();
try {
Project project = CommonDataKeys.PROJECT.getData(context);
String title = DiffBundle.message("merge.files.dialog.title");
List<String> titles = ContainerUtil.list(files[0].getPresentableUrl(), files[1].getPresentableUrl(), files[2].getPresentableUrl());
VirtualFile outputFile = files[1];
List<VirtualFile> contents = ContainerUtil.list(files[0], files[1], files[2]);
MergeRequest request = diffRequestFactory.createMergeRequestFromFiles(project, outputFile, contents, title, titles, null);
request.putUserData(DiffUserDataKeys.HELP_ID, "cvs.merge");
DiffManager.getInstance().showMerge(project, request);
} catch (InvalidDiffRequestException err) {
Messages.showErrorDialog(err.getLocalizedMessage(), DiffBundle.message("merge.files.dialog.title"));
}
}
use of com.intellij.diff.merge.MergeRequest in project intellij-community by JetBrains.
the class ApplyPatchAction method applyOnly.
@NotNull
public static ApplyPatchStatus applyOnly(@Nullable final Project project, @NotNull final ApplyFilePatchBase patch, @Nullable final ApplyPatchContext context, @NotNull final VirtualFile file, @Nullable final CommitContext commitContext, boolean reverse, @Nullable String leftPanelTitle, @Nullable String rightPanelTitle) {
final ApplyFilePatch.Result result = tryApplyPatch(project, patch, context, file, commitContext);
final ApplyPatchStatus status = result.getStatus();
if (ApplyPatchStatus.ALREADY_APPLIED.equals(status) || ApplyPatchStatus.SUCCESS.equals(status)) {
return status;
}
final ApplyPatchForBaseRevisionTexts mergeData = result.getMergeData();
if (mergeData == null)
return status;
final Document document = FileDocumentManager.getInstance().getDocument(file);
if (document == null)
return ApplyPatchStatus.FAILURE;
String baseContent = toString(mergeData.getBase());
String localContent = toString(mergeData.getLocal());
String patchedContent = mergeData.getPatched();
if (localContent == null)
return ApplyPatchStatus.FAILURE;
final Ref<ApplyPatchStatus> applyPatchStatusReference = new Ref<>();
Consumer<MergeResult> callback = new Consumer<MergeResult>() {
@Override
public void consume(MergeResult result) {
FileDocumentManager.getInstance().saveDocument(document);
applyPatchStatusReference.setIfNull(result != MergeResult.CANCEL ? ApplyPatchStatus.SUCCESS : ApplyPatchStatus.FAILURE);
}
};
try {
MergeRequest request;
if (baseContent != null) {
if (reverse) {
if (leftPanelTitle == null)
leftPanelTitle = VcsBundle.message("patch.apply.conflict.patched.version");
if (rightPanelTitle == null)
rightPanelTitle = VcsBundle.message("patch.apply.conflict.local.version");
List<String> contents = ContainerUtil.list(patchedContent, baseContent, localContent);
List<String> titles = ContainerUtil.list(leftPanelTitle, null, rightPanelTitle);
request = PatchDiffRequestFactory.createMergeRequest(project, document, file, contents, null, titles, callback);
} else {
request = PatchDiffRequestFactory.createMergeRequest(project, document, file, baseContent, localContent, patchedContent, callback);
}
} else {
TextFilePatch textPatch = (TextFilePatch) patch.getPatch();
final GenericPatchApplier applier = new GenericPatchApplier(localContent, textPatch.getHunks());
applier.execute();
final AppliedTextPatch appliedTextPatch = AppliedTextPatch.create(applier.getAppliedInfo());
request = PatchDiffRequestFactory.createBadMergeRequest(project, document, file, localContent, appliedTextPatch, callback);
}
request.putUserData(DiffUserDataKeysEx.MERGE_ACTION_CAPTIONS, new Function<MergeResult, String>() {
@Override
public String fun(MergeResult result) {
return result.equals(MergeResult.CANCEL) ? "Abort..." : null;
}
});
request.putUserData(DiffUserDataKeysEx.MERGE_CANCEL_HANDLER, new Condition<MergeTool.MergeViewer>() {
@Override
public boolean value(MergeTool.MergeViewer viewer) {
int result = Messages.showYesNoCancelDialog(viewer.getComponent().getRootPane(), XmlStringUtil.wrapInHtml("Would you like to <u>A</u>bort&Rollback applying patch action or <u>S</u>kip this file?"), "Close Merge", "_Abort", "_Skip", "Cancel", Messages.getQuestionIcon());
if (result == Messages.YES) {
applyPatchStatusReference.set(ApplyPatchStatus.ABORT);
} else if (result == Messages.NO) {
applyPatchStatusReference.set(ApplyPatchStatus.SKIP);
}
return result != Messages.CANCEL;
}
});
DiffManager.getInstance().showMerge(project, request);
return applyPatchStatusReference.get();
} catch (InvalidDiffRequestException e) {
LOG.warn(e);
return ApplyPatchStatus.FAILURE;
}
}
use of com.intellij.diff.merge.MergeRequest in project intellij-community by JetBrains.
the class MultipleFileMergeDialog method showMergeDialog.
private void showMergeDialog() {
DiffRequestFactory requestFactory = DiffRequestFactory.getInstance();
Collection<VirtualFile> files = myTable.getSelection();
if (!beforeResolve(files)) {
return;
}
for (final VirtualFile file : files) {
final MergeData mergeData;
try {
mergeData = myProvider.loadRevisions(file);
} catch (VcsException ex) {
Messages.showErrorDialog(myRootPanel, "Error loading revisions to merge: " + ex.getMessage());
break;
}
if (mergeData.CURRENT == null || mergeData.LAST == null || mergeData.ORIGINAL == null) {
Messages.showErrorDialog(myRootPanel, "Error loading revisions to merge");
break;
}
String leftTitle = myMergeDialogCustomizer.getLeftPanelTitle(file);
String baseTitle = myMergeDialogCustomizer.getCenterPanelTitle(file);
String rightTitle = myMergeDialogCustomizer.getRightPanelTitle(file, mergeData.LAST_REVISION_NUMBER);
String title = myMergeDialogCustomizer.getMergeWindowTitle(file);
final List<byte[]> byteContents = ContainerUtil.list(mergeData.CURRENT, mergeData.ORIGINAL, mergeData.LAST);
List<String> contentTitles = ContainerUtil.list(leftTitle, baseTitle, rightTitle);
Consumer<MergeResult> callback = result -> {
Document document = FileDocumentManager.getInstance().getCachedDocument(file);
if (document != null)
FileDocumentManager.getInstance().saveDocument(document);
checkMarkModifiedProject(file);
if (result != MergeResult.CANCEL) {
ApplicationManager.getApplication().runWriteAction(() -> {
markFileProcessed(file, getSessionResolution(result));
});
}
};
MergeRequest request;
try {
if (myProvider.isBinary(file)) {
// respect MIME-types in svn
request = requestFactory.createBinaryMergeRequest(myProject, file, byteContents, title, contentTitles, callback);
} else {
request = requestFactory.createMergeRequest(myProject, file, byteContents, title, contentTitles, callback);
}
MergeUtil.putRevisionInfos(request, mergeData);
} catch (InvalidDiffRequestException e) {
LOG.error(e);
Messages.showErrorDialog(myRootPanel, "Can't show merge dialog");
break;
}
DiffManager.getInstance().showMerge(myProject, request);
}
updateModelFromFiles();
}
use of com.intellij.diff.merge.MergeRequest in project intellij-community by JetBrains.
the class MergeApplication method processCommand.
@Override
public void processCommand(@NotNull String[] args, @Nullable String currentDirectory) throws Exception {
Project project = getProject();
List<String> filePaths = Arrays.asList(args).subList(1, args.length);
List<VirtualFile> files = findFiles(filePaths, currentDirectory);
// left, base, right
List<VirtualFile> contents = ContainerUtil.list(files.get(0), files.get(2), files.get(1));
VirtualFile outputFile = files.get(files.size() - 1);
MergeRequest request = DiffRequestFactory.getInstance().createMergeRequestFromFiles(project, outputFile, contents, null);
DiffManagerEx.getInstance().showMergeBuiltin(project, request);
Document document = FileDocumentManager.getInstance().getCachedDocument(outputFile);
if (document != null)
FileDocumentManager.getInstance().saveDocument(document);
}
Aggregations