Package org.eclipse.jgit.treewalk

Examples of org.eclipse.jgit.treewalk.TreeWalk


  @Test
  public void diffCommits() throws Exception {
    Repository repo = new FileRepository(testRepo);
    RevCommit commit1 = add("test.txt", "content");
    RevCommit commit2 = add("test.txt", "content2");
    TreeWalk walk = TreeUtils.diffWithCommits(repo, commit1, commit2);
    assertNotNull(walk);
    assertEquals(2, walk.getTreeCount());
    assertTrue(walk.next());
    assertEquals("test.txt", walk.getPathString());
    assertEquals(BlobUtils.getId(repo, commit1, "test.txt"),
        walk.getObjectId(0));
    assertEquals(BlobUtils.getId(repo, commit2, "test.txt"),
        walk.getObjectId(1));
    assertFalse(walk.next());
  }
View Full Code Here


   * @param path
   * @return blob id, null if not present
   */
  protected static ObjectId lookupId(final Repository repository,
      final RevCommit commit, final String path) {
    final TreeWalk walk;
    try {
      walk = TreeWalk.forPath(repository, path, commit.getTree());
    } catch (IOException e) {
      throw new GitException(e, repository);
    }
    if (walk == null)
      return null;
    if ((walk.getRawMode(0) & TYPE_MASK) != TYPE_FILE)
      return null;
    return walk.getObjectId(0);
  }
View Full Code Here

   * @return tree walk
   * @throws IOException
   */
  protected static TreeWalk withParents(final ObjectReader reader,
      final RevWalk rWalk, final RevCommit commit) throws IOException {
    final TreeWalk walk = new TreeWalk(reader);
    final int parentCount = commit.getParentCount();
    switch (parentCount) {
    case 0:
      walk.addTree(new EmptyTreeIterator());
      break;
    case 1:
      walk.addTree(getTree(rWalk, commit.getParent(0)));
      break;
    default:
      final RevCommit[] parents = commit.getParents();
      for (int i = 0; i < parentCount; i++)
        walk.addTree(getTree(rWalk, parents[i]));
    }
    walk.addTree(getTree(rWalk, commit));
    return walk;
  }
View Full Code Here

   * @param commitId
   * @return tree walk
   */
  public static TreeWalk diffWithParents(final Repository repository,
      final AnyObjectId commitId) {
    final TreeWalk walk = withParents(repository, commitId);
    walk.setFilter(ANY_DIFF);
    return walk;
  }
View Full Code Here

   * @param commit
   * @return tree walk
   */
  public static TreeWalk diffWithParents(final RevWalk walk,
      final RevCommit commit) {
    final TreeWalk treeWalk = withParents(walk, commit);
    treeWalk.setFilter(ANY_DIFF);
    return treeWalk;
  }
View Full Code Here

   * @param revision
   * @return tree walk
   */
  public static TreeWalk diffWithParents(final Repository repository,
      final String revision) {
    final TreeWalk walk = withParents(repository, revision);
    walk.setFilter(ANY_DIFF);
    return walk;
  }
View Full Code Here

          Assert.formatNotNull("Revisions"));
    if (revisions.length == 0)
      throw new IllegalArgumentException(
          Assert.formatNotEmpty("Revisions"));

    final TreeWalk walk = new TreeWalk(repository);
    try {
      for (String revision : revisions)
        walk.addTree(CommitUtils.getCommit(repository, revision)
            .getTree());
    } catch (IOException e) {
      throw new GitException(e, repository);
    }
    return walk;
View Full Code Here

    if (commits == null)
      throw new IllegalArgumentException(Assert.formatNotNull("Commits"));
    if (commits.length == 0)
      throw new IllegalArgumentException(Assert.formatNotEmpty("Commits"));

    final TreeWalk walk = new TreeWalk(repository);
    try {
      for (ObjectId commit : commits)
        walk.addTree(CommitUtils.getCommit(repository, commit)
            .getTree());
    } catch (IOException e) {
      throw new GitException(e, repository);
    }
    return walk;
View Full Code Here

   * @param commits
   * @return tree walk
   */
  public static TreeWalk diffWithCommits(final Repository repository,
      final ObjectId... commits) {
    final TreeWalk walk = withCommits(repository, commits);
    walk.setFilter(ANY_DIFF);
    return walk;
  }
View Full Code Here

   * @param revisions
   * @return tree walk
   */
  public static TreeWalk diffWithCommits(final Repository repository,
      final String... revisions) {
    final TreeWalk walk = withCommits(repository, revisions);
    walk.setFilter(ANY_DIFF);
    return walk;
  }
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.treewalk.TreeWalk

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.