/** * Create tree walk to compute differences for the given commits * <p> * Sub-classes may override this method to create a custom tree walk with * different filtering options set. * <p> * The last tree in the tree walk is assumed to be the tree of the current * commit * * @param walker * @param commit * @return tree walk */ protected TreeWalk createTreeWalk(final RevWalk walker, final RevCommit commit) { final TreeWalk walk = TreeUtils.diffWithParents(walker, commit); walk.setRecursive(true); return walk; }
/** * Create a tree walk configured to diff the given commit revisions * * @param repository * @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; }
/** * Create a tree walk configured to diff the given commit against all the * parent commits. * * @param repository * @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; }
try { walk.addTree(treeId); if (!visit(repository, walk, id, null, visitor)) return false; } catch (IOException e) {
/** * Get the id of the tree at the path in the given commit * * @param repository * @param commitId * @param path * @return tree id or null if no tree id at path */ public static ObjectId getId(final Repository repository, final ObjectId commitId, final String path) { if (repository == null) throw new IllegalArgumentException( Assert.formatNotNull("Repository")); if (commitId == null) throw new IllegalArgumentException( Assert.formatNotNull("Commit Id")); if (path == null) throw new IllegalArgumentException(Assert.formatNotNull("Path")); if (path.length() == 0) throw new IllegalArgumentException(Assert.formatNotNull("Path")); final RevCommit commit = CommitUtils.parse(repository, commitId); return lookupId(repository, commit, path); }
/** * Create a tree walk with the commit's parents. * * @param reader * @param rWalk * @param commit * @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; }
private static boolean visit(final Repository repository, final TreeWalk walk, final MutableObjectId id, final String path, final ITreeVisitor visitor) throws IOException { while (walk.next()) { if (walk.isPostChildren()) break; if (walk.isSubtree()) { final String subTreePath = walk.getPathString(); walk.enterSubtree(); if (!visit(repository, walk, id, subTreePath, visitor)) return false; } walk.getObjectId(id, 0); if (!visitor.accept(walk.getFileMode(0), path, walk.getNameString(), id)) return false; } return true; } }
/** * Get the id of the tree at the path in the given revision * * @param repository * @param revision * @param path * @return tree id or null if no tree id at path */ public static ObjectId getId(final Repository repository, final String revision, final String path) { if (repository == null) throw new IllegalArgumentException( Assert.formatNotNull("Repository")); if (revision == null) throw new IllegalArgumentException(Assert.formatNotNull("Revision")); if (revision.length() == 0) throw new IllegalArgumentException( Assert.formatNotEmpty("Revision")); if (path == null) throw new IllegalArgumentException(Assert.formatNotNull("Path")); if (path.length() == 0) throw new IllegalArgumentException(Assert.formatNotNull("Path")); final RevCommit commit = CommitUtils.parse(repository, CommitUtils.strictResolve(repository, revision)); return lookupId(repository, commit, path); }
/** * Create a tree walk configured to diff the given revision against all the * parent commits. * * @param repository * @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; }
/** * Create a tree walk configured to diff the given commits * * @param repository * @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; }
public boolean include(final RevWalk walker, final RevCommit commit) throws IOException { final TreeWalk walk = TreeUtils.diffWithParents(walker, commit); final MutableObjectId id = new MutableObjectId(); final ObjectId zero = ObjectId.zeroId(); final DuplicateContainer dupes = new DuplicateContainer(commit); while (walk.next()) { if (!walk.isSubtree()) continue; final String path = walk.getPathString(); for (int i = 0; i < walk.getTreeCount(); i++) { walk.getObjectId(id, i); if (!zero.equals(id)) dupes.include(id.toObjectId(), path); } walk.enterSubtree(); } if (dupes.validate()) duplicates.put(commit, dupes); return true; }
/** * Create a tree walk configured to diff the given commit against all the * parent commits. * * @param walk * @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; }
/** * Create a tree walk with all the trees from the given commit's parents. * * @param walk * @param commit * @return tree walk */ public static TreeWalk withParents(final RevWalk walk, final RevCommit commit) { if (walk == null) throw new IllegalArgumentException(Assert.formatNotNull("Walk")); if (commit == null) throw new IllegalArgumentException(Assert.formatNotNull("Commit")); try { return withParents(walk.getObjectReader(), walk, commit); } catch (IOException e) { throw new GitException(e, null); } }
/** * Create a tree walk with all the trees from the given revision's commit * parents. * * @param repository * @param revision * @return tree walk */ public static TreeWalk withParents(final Repository repository, final String revision) { if (repository == null) throw new IllegalArgumentException( Assert.formatNotNull("Repository")); if (revision == null) throw new IllegalArgumentException(Assert.formatNotNull("Revision")); if (revision.length() == 0) throw new IllegalArgumentException( Assert.formatNotEmpty("Revision")); final ObjectId commit = CommitUtils.strictResolve(repository, revision); final ObjectReader reader = repository.newObjectReader(); final RevWalk walk = new RevWalk(reader); try { return withParents(reader, walk, walk.parseCommit(commit)); } catch (IOException e) { walk.close(); throw new GitException(e, repository); } }
/** * Create a tree walk with all the trees from the given commit's parents. * * @param repository * @param commitId * @return tree walk */ public static TreeWalk withParents(final Repository repository, final AnyObjectId commitId) { if (repository == null) throw new IllegalArgumentException( Assert.formatNotNull("Repository")); if (commitId == null) throw new IllegalArgumentException( Assert.formatNotNull("Commit id")); final ObjectReader reader = repository.newObjectReader(); final RevWalk walk = new RevWalk(reader); try { return withParents(reader, walk, walk.parseCommit(commitId)); } catch (IOException e) { walk.close(); throw new GitException(e, repository); } }