コード例 #1
0
 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);
   }
 }
コード例 #2
0
 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);
   }
 }
コード例 #3
0
 private void showDirDiffDialog(
     @NotNull FilePath path,
     @Nullable String hash1,
     @Nullable String hash2,
     @NotNull List<Change> diff) {
   DialogBuilder dialogBuilder = new DialogBuilder(myProject);
   String title;
   if (hash2 != null) {
     if (hash1 != null) {
       title =
           String.format(
               "Difference between %s and %s in %s",
               GitUtil.getShortHash(hash1), GitUtil.getShortHash(hash2), path.getName());
     } else {
       title =
           String.format("Initial commit %s in %s", GitUtil.getShortHash(hash2), path.getName());
     }
   } else {
     LOG.assertTrue(hash1 != null, "hash1 and hash2 can't both be null. Path: " + path);
     title =
         String.format(
             "Difference between %s and local version in %s",
             GitUtil.getShortHash(hash1), path.getName());
   }
   dialogBuilder.setTitle(title);
   dialogBuilder.setActionDescriptors(
       new DialogBuilder.ActionDescriptor[] {new DialogBuilder.CloseDialogAction()});
   final ChangesBrowser changesBrowser =
       new ChangesBrowser(
           myProject,
           null,
           diff,
           null,
           false,
           true,
           null,
           ChangesBrowser.MyUseCase.COMMITTED_CHANGES,
           null);
   changesBrowser.setChangesToDisplay(diff);
   dialogBuilder.setCenterPanel(changesBrowser);
   dialogBuilder.show();
 }
コード例 #4
0
 private void createOrSelectContentIfNeeded() {
   ToolWindow toolWindow = getToolWindow(myVcs.getProject());
   if (myRefresherI.isFirstTime()) {
     ContentManager manager = toolWindow.getContentManager();
     boolean selectedExistingContent =
         ContentUtilEx.selectContent(manager, myFileHistoryPanel, true);
     if (!selectedExistingContent) {
       ContentUtilEx.addTabbedContent(
           manager, myFileHistoryPanel, "History", myPath.getName(), true);
     }
     toolWindow.activate(null);
   }
 }
コード例 #5
0
  public void reportAppendableHistory(
      FilePath path, final VcsAppendableHistorySessionPartner partner) throws VcsException {
    final FilePath committedPath = ChangesUtil.getCommittedPath(myVcs.getProject(), path);

    final LogLoader logLoader;
    if (path.isNonLocal()) {
      logLoader = new RepositoryLoader(myVcs, path);
    } else {
      logLoader = new LocalLoader(myVcs, path);
    }

    try {
      logLoader.preliminary();
    } catch (SVNCancelException e) {
      return;
    } catch (SVNException e) {
      throw new VcsException(e);
    }
    logLoader.initSupports15();

    final MyHistorySession historySession =
        new MyHistorySession(
            Collections.<VcsFileRevision>emptyList(),
            committedPath,
            Boolean.TRUE.equals(logLoader.mySupport15),
            null);

    final Ref<Boolean> sessionReported = new Ref<Boolean>();
    final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
    if (indicator != null) {
      indicator.setText(SvnBundle.message("progress.text2.collecting.history", path.getName()));
    }
    final Consumer<VcsFileRevision> consumer =
        new Consumer<VcsFileRevision>() {
          public void consume(VcsFileRevision vcsFileRevision) {
            if (!Boolean.TRUE.equals(sessionReported.get())) {
              partner.reportCreatedEmptySession(historySession);
              sessionReported.set(true);
            }
            partner.acceptRevision(vcsFileRevision);
          }
        };

    logLoader.setConsumer(consumer);
    logLoader.load();
    logLoader.check();
  }
コード例 #6
0
  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;
  }
コード例 #7
0
  /**
   * 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);
  }
コード例 #8
0
 @Override
 public String toString() {
   return path.getName() + ":" + revision.getShortRev();
 }
コード例 #9
0
  public void reportAppendableHistory(
      FilePath path,
      final VcsAppendableHistorySessionPartner partner,
      @Nullable final SVNRevision from,
      @Nullable final SVNRevision to,
      final int limit,
      SVNRevision peg,
      final boolean forceBackwards)
      throws VcsException {
    FilePath committedPath = path;
    Change change = ChangeListManager.getInstance(myVcs.getProject()).getChange(path);
    if (change != null) {
      final ContentRevision beforeRevision = change.getBeforeRevision();
      final ContentRevision afterRevision = change.getAfterRevision();
      if (beforeRevision != null
          && afterRevision != null
          && !beforeRevision.getFile().equals(afterRevision.getFile())
          && afterRevision.getFile().equals(path)) {
        committedPath = beforeRevision.getFile();
      }
      // revision can be VcsRevisionNumber.NULL
      if (peg == null
          && change.getBeforeRevision() != null
          && change.getBeforeRevision().getRevisionNumber() instanceof SvnRevisionNumber) {
        peg = ((SvnRevisionNumber) change.getBeforeRevision().getRevisionNumber()).getRevision();
      }
    }

    final boolean showMergeSources =
        SvnConfiguration.getInstance(myVcs.getProject()).isShowMergeSourcesInAnnotate();
    final LogLoader logLoader;
    if (path.isNonLocal()) {
      logLoader =
          new RepositoryLoader(
              myVcs, committedPath, from, to, limit, peg, forceBackwards, showMergeSources);
    } else {
      logLoader = new LocalLoader(myVcs, committedPath, from, to, limit, peg, showMergeSources);
    }

    try {
      logLoader.preliminary();
    } catch (SVNCancelException e) {
      throw new VcsException(e);
    } catch (SVNException e) {
      throw new VcsException(e);
    }
    logLoader.check();
    if (showMergeSources) {
      logLoader.initSupports15();
    }

    final SvnHistorySession historySession =
        new SvnHistorySession(
            myVcs,
            Collections.<VcsFileRevision>emptyList(),
            committedPath,
            showMergeSources && Boolean.TRUE.equals(logLoader.mySupport15),
            null,
            false,
            !path.isNonLocal());

    final Ref<Boolean> sessionReported = new Ref<Boolean>();
    final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
    if (indicator != null) {
      indicator.setText(SvnBundle.message("progress.text2.collecting.history", path.getName()));
    }
    final Consumer<VcsFileRevision> consumer =
        new Consumer<VcsFileRevision>() {
          @Override
          public void consume(VcsFileRevision vcsFileRevision) {
            if (!Boolean.TRUE.equals(sessionReported.get())) {
              partner.reportCreatedEmptySession(historySession);
              sessionReported.set(true);
            }
            partner.acceptRevision(vcsFileRevision);
          }
        };

    logLoader.setConsumer(consumer);
    logLoader.load();
    logLoader.check();
  }