Example usage for org.eclipse.jgit.dircache DirCacheIterator getEntryObjectId

List of usage examples for org.eclipse.jgit.dircache DirCacheIterator getEntryObjectId

Introduction

In this page you can find the example usage for org.eclipse.jgit.dircache DirCacheIterator getEntryObjectId.

Prototype

public ObjectId getEntryObjectId() 

Source Link

Document

Get the object id of the current entry.

Usage

From source file:de.fkoeberle.autocommit.git.GitRepositoryAdapter.java

License:Open Source License

private void visitHeadIndexDelta(GitFileSetDeltaVisitor... visitors) throws IOException {
    TreeWalk treeWalk = new TreeWalk(repository);
    treeWalk.setRecursive(true);/*from   w w  w  . j  a v a 2 s .c  om*/
    ObjectId headTreeId = repository.resolve(Constants.HEAD);
    DirCache dirCache = repository.readDirCache();
    DirCacheIterator dirCacheTree = new DirCacheIterator(dirCache);
    int dirCacheTreeIndex = treeWalk.addTree(dirCacheTree);

    if (headTreeId == null) {
        while (treeWalk.next()) {
            DirCacheIterator dirCacheMatch = treeWalk.getTree(dirCacheTreeIndex, DirCacheIterator.class);
            final String path = treeWalk.getPathString();
            ObjectId newObjectId = dirCacheMatch.getEntryObjectId();
            for (GitFileSetDeltaVisitor visitor : visitors) {
                visitor.visitAddedFile(path, newObjectId);
            }
        }
    } else {
        RevWalk revWalk = new RevWalk(repository);
        RevTree revTree = revWalk.parseTree(headTreeId);
        int revTreeIndex = treeWalk.addTree(revTree);
        TreeFilter filter = AndTreeFilter.create(TreeFilter.ANY_DIFF,
                new SkipWorkTreeFilter(dirCacheTreeIndex));
        treeWalk.setFilter(filter);

        while (treeWalk.next()) {
            AbstractTreeIterator headMatch = treeWalk.getTree(revTreeIndex, AbstractTreeIterator.class);
            DirCacheIterator dirCacheMatch = treeWalk.getTree(dirCacheTreeIndex, DirCacheIterator.class);
            final String path = treeWalk.getPathString();
            visitDeltaWithAll(path, headMatch, dirCacheMatch, visitors);
        }
    }
}