public static boolean isBinaryChange(Change change) { if (change.hasOtherLayers()) return false; // +- final ContentRevision bRev = change.getBeforeRevision(); final ContentRevision aRev = change.getAfterRevision(); return (aRev == null || aRev instanceof BinaryContentRevision) && (bRev == null || bRev instanceof BinaryContentRevision); }
public static BeforeAfter<DiffContent> createBinaryDiffContents( final Project project, final Change change) throws VcsException { final FilePath filePath = ChangesUtil.getFilePath(change); try { return new BeforeAfter<DiffContent>( createBinaryFileContent(project, change.getBeforeRevision(), filePath.getName()), createBinaryFileContent(project, change.getAfterRevision(), filePath.getName())); } catch (IOException e) { throw new VcsException(e); } }
private static SimpleDiffRequest createBinaryDiffRequest( final Project project, final Change change) throws VcsException { final FilePath filePath = ChangesUtil.getFilePath(change); final SimpleDiffRequest request = new SimpleDiffRequest(project, filePath.getPath()); try { request.setContents( createBinaryFileContent(project, change.getBeforeRevision(), filePath.getName()), createBinaryFileContent(project, change.getAfterRevision(), filePath.getName())); return request; } catch (IOException e) { throw new VcsException(e); } }
private boolean checkIfThereAreFakeRevisions(final Project project, final Change[] changes) { boolean needsConvertion = false; for (Change change : changes) { final ContentRevision beforeRevision = change.getBeforeRevision(); final ContentRevision afterRevision = change.getAfterRevision(); if (beforeRevision instanceof FakeRevision) { VcsDirtyScopeManager.getInstance(project).fileDirty(beforeRevision.getFile()); needsConvertion = true; } if (afterRevision instanceof FakeRevision) { VcsDirtyScopeManager.getInstance(project).fileDirty(afterRevision.getFile()); needsConvertion = true; } } return needsConvertion; }
private static boolean checkNotifyBinaryDiff(final Change selectedChange) { final ContentRevision beforeRevision = selectedChange.getBeforeRevision(); final ContentRevision afterRevision = selectedChange.getAfterRevision(); if (beforeRevision instanceof BinaryContentRevision && afterRevision instanceof BinaryContentRevision) { try { byte[] beforeContent = ((BinaryContentRevision) beforeRevision).getBinaryContent(); byte[] afterContent = ((BinaryContentRevision) afterRevision).getBinaryContent(); if (Arrays.equals(beforeContent, afterContent)) { Messages.showInfoMessage( VcsBundle.message("message.text.binary.versions.are.identical"), VcsBundle.message("message.title.diff")); } else { Messages.showInfoMessage( VcsBundle.message("message.text.binary.versions.are.different"), VcsBundle.message("message.title.diff")); } } catch (VcsException e) { Messages.showInfoMessage(e.getMessage(), VcsBundle.message("message.title.diff")); } return true; } return false; }
public static boolean isBinaryChangeAndCanShow(Project project, Change change) { // todo bug here would appear when there would be another diff providers for bimary revisions return isBinaryChange(change) && (change.getAfterRevision() == null || BinaryDiffTool.canShow(project, change.getVirtualFile())); }