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

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

Introduction

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

Prototype

public IndexDiffFilter(int dirCacheIndex, int workingTreeIndex, boolean honorIgnores) 

Source Link

Document

Creates a new instance of this filter.

Usage

From source file:com.beck.ep.team.git.GitListBuilder.java

License:BSD License

private String[] listIgnored(Repository rep, RevWalk rw, TreeWalk tw, int cutPrefixLen) throws Exception {
    addTree(GitModeMenuMgr.MODE_STAGING, null, rep, rw, tw);
    int workingTreeIndex = addTree(GitModeMenuMgr.MODE_WORKING_AREA, null, rep, rw, tw);
    IndexDiffFilter filter = new IndexDiffFilter(0, workingTreeIndex, true);
    tw.setFilter(filter);// w  ww .j ava 2  s  . c om
    tw.setRecursive(true);
    while (tw.next()) {
        //just loop it...
    }
    Set<String> s = filter.getIgnoredPaths();
    return s.toArray(new String[s.size()]);
}

From source file:org.eclipse.ptp.internal.rdt.sync.git.core.GitSyncFileFilter.java

License:Open Source License

/**
 * Get all different files (modified/changed, missing/removed, untracked/added)
 * /* w  w  w.  jav  a2  s.  c o m*/
 * assumes that no files are in conflict (don't call during merge)
 * 
 * @return different files
 * @throws IOException
 *          on file system problems
 */
public DiffFiles getDiffFiles() throws IOException {
    final int INDEX = 0;
    final int WORKDIR = 1;

    assert (!jgitRepo.inUnresolvedMergeState());

    Repository repo = jgitRepo.getRepository();
    TreeWalk treeWalk = new TreeWalk(repo);
    treeWalk.addTree(new DirCacheIterator(repo.readDirCache()));
    treeWalk.addTree(new FileTreeIterator(repo));

    // don't honor ignores - we do it manually instead. Doing it all with the filter
    // would require a WorkingTreeIterator that does the ignore handling correctly
    // (both directory including bugs 401161 and only using info/exclude, not .gitignore)
    treeWalk.setFilter(new IndexDiffFilter(INDEX, WORKDIR, false));
    DiffFiles diffFiles = new DiffFiles();
    int ignoreDepth = Integer.MAX_VALUE; // if the current subtree is ignored - than this is the depth at which ignoring
    // starts
    while (treeWalk.next()) {
        DirCacheIterator dirCacheIterator = treeWalk.getTree(INDEX, DirCacheIterator.class);
        String path = treeWalk.getPathString();
        boolean isSubtree = treeWalk.isSubtree();
        int depth = treeWalk.getDepth();
        if (dirCacheIterator != null || // in index => either missing or modified
                !shouldIgnore(path, isSubtree)) { // not in index => untracked
            if (depth <= ignoreDepth) {
                ignoreDepth = Integer.MAX_VALUE;
            }
            if (dirCacheIterator != null && isSubtree && ignoreDepth == Integer.MAX_VALUE
                    && shouldIgnore(path, isSubtree)) {
                ignoreDepth = depth;
            }
            if (isSubtree) {
                treeWalk.enterSubtree();
                diffFiles.dirSet.add(path);
            } else if (dirCacheIterator != null || ignoreDepth == Integer.MAX_VALUE) {
                WorkingTreeIterator workTreeIter = treeWalk.getTree(WORKDIR, WorkingTreeIterator.class);
                if (workTreeIter != null) {
                    diffFiles.added.add(path);
                } else {
                    diffFiles.removed.add(path);
                }
            }
        }
    }
    return diffFiles;
}