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);
}
}
Aggregations