Example usage for org.eclipse.jgit.treewalk.filter SkipWorkTreeFilter SkipWorkTreeFilter

List of usage examples for org.eclipse.jgit.treewalk.filter SkipWorkTreeFilter SkipWorkTreeFilter

Introduction

In this page you can find the example usage for org.eclipse.jgit.treewalk.filter SkipWorkTreeFilter SkipWorkTreeFilter.

Prototype

public SkipWorkTreeFilter(int treeIdx) 

Source Link

Document

Create a filter to work on the specified DirCacheIterator.

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   ww w  .j  ava  2s . 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);
        }
    }
}

From source file:org.exist.git.xquery.Status.java

License:Open Source License

public void diff(final Repository repository, final String revstr,
        final WorkingTreeIterator initialWorkingTreeIterator, final StatusBuilder builder, final String folder,
        boolean recursive) throws IOException {

    RevTree tree = null;//from w  w w .ja v a  2s .co  m

    ObjectId objectId = repository.resolve(revstr);
    if (objectId != null)
        tree = new RevWalk(repository).parseTree(objectId);
    else
        tree = null;

    PathFilter filter = folder == null || folder.isEmpty() ? null : PathFilter.create(folder);
    IndexDiffFilter indexDiffFilter;

    DirCache dirCache = repository.readDirCache();

    TreeWalk treeWalk = new TreeWalk(repository);
    //      TreeWalk treeWalk = TreeWalk.forPath(repository, folder, tree);
    treeWalk.setRecursive(recursive);
    // add the trees (tree, dirchache, workdir)
    if (tree != null)
        treeWalk.addTree(tree);
    else
        treeWalk.addTree(new EmptyTreeIterator());
    treeWalk.addTree(new DirCacheIterator(dirCache));
    treeWalk.addTree(initialWorkingTreeIterator);
    Collection<TreeFilter> filters = new ArrayList<TreeFilter>(4);

    if (filter != null)
        filters.add(filter);
    filters.add(new SkipWorkTreeFilter(INDEX));
    indexDiffFilter = new IndexDiffFilter(INDEX, WORKDIR);
    filters.add(indexDiffFilter);
    treeWalk.setFilter(AndTreeFilter.create(filters));
    if (filter != null) {
        while (treeWalk.next()) {
            if (filter.include(treeWalk)) {
                if (filter.isDone(treeWalk)) {
                    if (treeWalk.isSubtree()) {
                        treeWalk.enterSubtree();
                    }
                    break;
                } else if (treeWalk.isSubtree()) {
                    treeWalk.enterSubtree();
                }
            }
        }
    }

    while (treeWalk.next()) {
        AbstractTreeIterator treeIterator = treeWalk.getTree(TREE, AbstractTreeIterator.class);
        DirCacheIterator dirCacheIterator = treeWalk.getTree(INDEX, DirCacheIterator.class);
        WorkingTreeIterator workingTreeIterator = treeWalk.getTree(WORKDIR, WorkingTreeIterator.class);

        if (dirCacheIterator != null) {
            final DirCacheEntry dirCacheEntry = dirCacheIterator.getDirCacheEntry();
            if (dirCacheEntry != null && dirCacheEntry.getStage() > 0) {
                builder.conflict(treeWalk.getFileMode(2), treeWalk.getPathString());
                continue;
            }
        }

        if (treeIterator != null) {
            if (dirCacheIterator != null) {
                if (!treeIterator.idEqual(dirCacheIterator)
                        || treeIterator.getEntryRawMode() != dirCacheIterator.getEntryRawMode()) {
                    // in repo, in index, content diff => changed
                    builder.changed(treeWalk.getFileMode(2), treeWalk.getPathString());
                    continue;
                }
            } else {
                // in repo, not in index => removed
                builder.removed(treeWalk.getFileMode(2), treeWalk.getPathString());
                if (workingTreeIterator != null) //XXX: 2 statuses
                    builder.untracked(treeWalk.getFileMode(2), treeWalk.getPathString());
                continue;
            }
        } else {
            if (dirCacheIterator != null) {
                // not in repo, in index => added
                builder.added(treeWalk.getFileMode(2), treeWalk.getPathString());
                continue;
            } else {
                // not in repo, not in index => untracked
                if (workingTreeIterator != null && !workingTreeIterator.isEntryIgnored()) {
                    builder.untracked(treeWalk.getFileMode(2), treeWalk.getPathString());
                    continue;
                }
            }
        }

        if (dirCacheIterator != null) {
            if (workingTreeIterator == null) {
                // in index, not in workdir => missing
                builder.missing(treeWalk.getFileMode(2), treeWalk.getPathString());
                continue;
            } else {
                if (dirCacheIterator.getDirCacheEntry() == null) {
                    //XXX: null on collections - to fix
                    //                  builder.unchanged(treeWalk.getFileMode(2), treeWalk.getPathString());

                } else if (workingTreeIterator.isModified(dirCacheIterator.getDirCacheEntry(), true)) {
                    // in index, in workdir, content differs => modified
                    builder.modified(treeWalk.getFileMode(2), treeWalk.getPathString());
                    continue;
                }
            }
        }
        builder.unchanged(treeWalk.getFileMode(2), treeWalk.getPathString());
    }

    //      for (String path : indexDiffFilter.getUntrackedFolders()) {
    //         builder.untrackedFolders(path);
    //      }
    //      
    for (String path : indexDiffFilter.getIgnoredPaths()) {
        //XXX: to fix FileMode
        builder.ignored(FileMode.REGULAR_FILE, path);
    }
}