Exemple #1
0
  private IFileRevision[] buildRevisions(final IProgressMonitor monitor, final int flags) {
    if (walk == null) return NO_REVISIONS;

    final Repository db = walk.getRepository();
    final RevCommit root;
    try {
      final AnyObjectId headId = db.resolve(Constants.HEAD);
      if (headId == null) {
        Activator.logError(
            NLS.bind(
                CoreText.GitFileHistory_noHeadRevisionAvailable, resource.getProject().getName()),
            null);
        return NO_REVISIONS;
      }

      root = walk.parseCommit(headId);
      if ((flags & SINGLE_REVISION) == SINGLE_REVISION) {
        // If all Eclipse wants is one revision it probably is
        // for the editor "quick diff" feature. We can pass off
        // just the repository HEAD, even though it may not be
        // the revision that most recently modified the path.
        //
        final CommitFileRevision single;
        single = new CommitFileRevision(db, root, gitPath);
        return new IFileRevision[] {single};
      }

      walk.markStart(root);
    } catch (IOException e) {
      Activator.logError(
          NLS.bind(CoreText.GitFileHistory_invalidHeadRevision, resource.getProject().getName()),
          e);
      return NO_REVISIONS;
    }

    final KidCommitList list = new KidCommitList();
    list.source(walk);
    try {
      for (; ; ) {
        final int oldsz = list.size();
        list.fillTo(oldsz + BATCH_SIZE - 1);
        if (oldsz == list.size()) break;
        if (monitor != null && monitor.isCanceled()) break;
      }
    } catch (IOException e) {
      Activator.logError(
          NLS.bind(CoreText.GitFileHistory_errorParsingHistory, resource.getFullPath()), e);
      return NO_REVISIONS;
    }

    final IFileRevision[] r = new IFileRevision[list.size()];
    for (int i = 0; i < r.length; i++) r[i] = new CommitFileRevision(db, list.get(i), gitPath);
    return r;
  }
Exemple #2
0
  private KidWalk buildWalk() {
    final RepositoryMapping rm = RepositoryMapping.getMapping(resource);
    if (rm == null) {
      Activator.logError(
          NLS.bind(CoreText.GitFileHistory_gitNotAttached, resource.getProject().getName()), null);
      return null;
    }

    final KidWalk w = new KidWalk(rm.getRepository());
    gitPath = rm.getRepoRelativePath(resource);
    w.setTreeFilter(
        AndTreeFilter.create(
            PathFilterGroup.createFromStrings(Collections.singleton(gitPath)),
            TreeFilter.ANY_DIFF));
    return w;
  }
Exemple #3
0
  public IFileRevision[] getContributors(final IFileRevision ifr) {
    if (!(ifr instanceof CommitFileRevision)) return NO_REVISIONS;

    final CommitFileRevision rev = (CommitFileRevision) ifr;
    final Repository db = walk.getRepository();
    final String p = rev.getGitPath();
    final RevCommit c = rev.getRevCommit();
    final IFileRevision[] r = new IFileRevision[c.getParentCount()];
    for (int i = 0; i < r.length; i++) r[i] = new CommitFileRevision(db, c.getParent(i), p);
    return r;
  }
Exemple #4
0
  public IFileRevision getFileRevision(final String id) {
    if (id == null
        || id.equals("") // $NON-NLS-1$
        || GitFileRevision.WORKSPACE.equals(id)) return new WorkspaceFileRevision(resource);
    if (GitFileRevision.INDEX.equals(id))
      return new IndexFileRevision(walk.getRepository(), gitPath);

    // Only return a revision if it was matched by this filtered history
    for (IFileRevision r : revisions) {
      if (r.getContentIdentifier().equals(id)) return r;
    }
    return null;
  }
Exemple #5
0
  public IFileRevision[] getTargets(final IFileRevision ifr) {
    if (!(ifr instanceof CommitFileRevision)) return NO_REVISIONS;

    final CommitFileRevision rev = (CommitFileRevision) ifr;
    final Repository db = walk.getRepository();
    final String p = rev.getGitPath();
    final RevCommit rc = rev.getRevCommit();
    if (!(rc instanceof KidCommit)) return NO_REVISIONS;

    final KidCommit c = (KidCommit) rc;
    final IFileRevision[] r = new IFileRevision[c.children.length];
    for (int i = 0; i < r.length; i++) r[i] = new CommitFileRevision(db, c.children[i], p);
    return r;
  }