Search in sources :

Example 1 with IndexDiffFilter

use of org.eclipse.jgit.treewalk.filter.IndexDiffFilter in project egit by eclipse.

the class WorkingTreeChangeCache method build.

/**
 * @param repo
 *            with should be scanned
 * @return list of changes in working tree
 */
public static Map<String, Change> build(Repository repo) {
    try (TreeWalk tw = new TreeWalk(repo)) {
        int fileNth = tw.addTree(new FileTreeIterator(repo));
        int cacheNth = tw.addTree(new DirCacheIterator(repo.readDirCache()));
        tw.setFilter(new IndexDiffFilter(cacheNth, fileNth));
        tw.setRecursive(true);
        Map<String, Change> result = new HashMap<String, Change>();
        MutableObjectId idBuf = new MutableObjectId();
        while (tw.next()) {
            Change change = new Change();
            change.name = tw.getNameString();
            tw.getObjectId(idBuf, 0);
            change.objectId = AbbreviatedObjectId.fromObjectId(idBuf);
            tw.getObjectId(idBuf, 1);
            change.remoteObjectId = AbbreviatedObjectId.fromObjectId(idBuf);
            calculateAndSetChangeKind(RIGHT, change);
            result.put(tw.getPathString(), change);
        }
        return result;
    } catch (IOException e) {
        Activator.logError(e.getMessage(), e);
        return new HashMap<String, GitCommitsModelCache.Change>(0);
    }
}
Also used : MutableObjectId(org.eclipse.jgit.lib.MutableObjectId) IndexDiffFilter(org.eclipse.jgit.treewalk.filter.IndexDiffFilter) HashMap(java.util.HashMap) DirCacheIterator(org.eclipse.jgit.dircache.DirCacheIterator) Change(org.eclipse.egit.core.synchronize.GitCommitsModelCache.Change) IOException(java.io.IOException) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) FileTreeIterator(org.eclipse.jgit.treewalk.FileTreeIterator)

Aggregations

IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Change (org.eclipse.egit.core.synchronize.GitCommitsModelCache.Change)1 DirCacheIterator (org.eclipse.jgit.dircache.DirCacheIterator)1 MutableObjectId (org.eclipse.jgit.lib.MutableObjectId)1 FileTreeIterator (org.eclipse.jgit.treewalk.FileTreeIterator)1 TreeWalk (org.eclipse.jgit.treewalk.TreeWalk)1 IndexDiffFilter (org.eclipse.jgit.treewalk.filter.IndexDiffFilter)1