@NotNull public static SvnContentRevision createRemote( @NotNull SvnVcs vcs, @NotNull FilePath file, @NotNull SVNRevision revision) { if (file.getFileType().isBinary()) { return new SvnBinaryContentRevision(vcs, file, revision, false); } return new SvnContentRevision(vcs, file, revision, false); }
@Override protected void renderIcon(FilePath path) { final String module = myModules.get(path.getVirtualFile()); if (module != null) { setIcon(PlatformIcons.CONTENT_ROOT_ICON_CLOSED); } else { if (path.isDirectory()) { setIcon(PlatformIcons.DIRECTORY_CLOSED_ICON); } else { setIcon(path.getFileType().getIcon()); } } }
public PreparedFragmentedContent getRanges(Change change) throws VcsException { final FilePath filePath = ChangesUtil.getFilePath(change); final RangesCalculator calculator = new RangesCalculator(); calculator.execute( change, filePath, myRangesCache, LineStatusTrackerManager.getInstance(myProject)); final VcsException exception = calculator.getException(); if (exception != null) { LOG.info(exception); throw exception; } List<BeforeAfter<TextRange>> ranges = calculator.getRanges(); if (ranges == null || ranges.isEmpty()) return null; FragmentedContent fragmentedContent = new FragmentedContent( calculator.getOldDocument(), calculator.getDocument(), ranges, change); VirtualFile file = filePath.getVirtualFile(); if (file == null) { filePath.hardRefresh(); file = filePath.getVirtualFile(); } final PreparedFragmentedContent preparedFragmentedContent = new PreparedFragmentedContent( myProject, fragmentedContent, filePath.getName(), filePath.getFileType(), change.getBeforeRevision() == null ? null : change.getBeforeRevision().getRevisionNumber(), change.getAfterRevision() == null ? null : change.getAfterRevision().getRevisionNumber(), filePath, file); return preparedFragmentedContent; }
/** * Invokes {@link com.intellij.openapi.diff.DiffManager#getDiffTool()} to show difference between * the given revisions of the given file. * * @param project project under vcs control. * @param filePath file which revisions are compared. * @param revision1 first revision - 'before', to the left. * @param revision2 second revision - 'after', to the right. * @throws com.intellij.openapi.vcs.VcsException * @throws java.io.IOException */ public static void showDiff( @NotNull final Project project, @NotNull FilePath filePath, @NotNull VcsFileRevision revision1, @NotNull VcsFileRevision revision2, @NotNull String title1, @NotNull String title2) throws VcsException, IOException { final byte[] content1 = loadRevisionContent(revision1); final byte[] content2 = loadRevisionContent(revision2); final SimpleDiffRequest diffData = new SimpleDiffRequest(project, filePath.getPresentableUrl()); diffData.addHint(DiffTool.HINT_SHOW_FRAME); final Document doc = filePath.getDocument(); final Charset charset = filePath.getCharset(); final FileType fileType = filePath.getFileType(); diffData.setContentTitles(title1, title2); final Ref<VirtualFile> f1 = new Ref<VirtualFile>(null); final Ref<VirtualFile> f2 = new Ref<VirtualFile>(null); if (fileType.isBinary()) { final File file1 = FileUtil.createTempFile(revision1.getRevisionNumber().asString(), filePath.getName()); final File file2 = FileUtil.createTempFile(revision2.getRevisionNumber().asString(), filePath.getName()); try { final FileOutputStream fos1 = new FileOutputStream(file1); fos1.write(content1); final FileOutputStream fos2 = new FileOutputStream(file2); fos2.write(content2); fos1.close(); fos2.close(); f1.set(LocalFileSystem.getInstance().findFileByIoFile(file1)); f2.set(LocalFileSystem.getInstance().findFileByIoFile(file2)); } catch (Exception e) { // } } if (f1.isNull() || f2.isNull()) { diffData.setContents( createContent(project, content1, revision1, doc, charset, fileType, filePath.getPath()), createContent(project, content2, revision2, doc, charset, fileType, filePath.getPath())); } else { diffData.setContents( createFileContent(project, f1.get(), revision1), createFileContent(project, f2.get(), revision2)); } WaitForProgressToShow.runOrInvokeLaterAboveProgress( new Runnable() { public void run() { DiffManager.getInstance().getDiffTool().show(diffData); if (!f1.isNull() || !f2.isNull()) { Disposer.register( project, new Disposable() { @Override public void dispose() { ApplicationManager.getApplication() .runWriteAction( new Runnable() { public void run() { try { if (!f1.isNull()) { f1.get().delete(this); } if (!f2.isNull()) { f2.get().delete(this); } } catch (IOException e) { // } } }); } }); } } }, null, project); }