diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java index 1e0a76468..1acfa3d68 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java @@ -3,6 +3,7 @@ * Copyright (C) 2007-2008, Robin Rosenberg * Copyright (C) 2010, Jens Baumgart * Copyright (C) 2013, Robin Stocker + * Copyright (C) 2014, Axel Richard * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -276,6 +277,8 @@ public class IndexDiff { private IgnoreSubmoduleMode ignoreSubmoduleMode = null; + private Map> fileModes = new HashMap>(); + /** * Construct an IndexDiff * @@ -425,6 +428,7 @@ public class IndexDiff { indexDiffFilter = new IndexDiffFilter(INDEX, WORKDIR); filters.add(indexDiffFilter); treeWalk.setFilter(AndTreeFilter.create(filters)); + fileModes.clear(); while (treeWalk.next()) { AbstractTreeIterator treeIterator = treeWalk.getTree(TREE, AbstractTreeIterator.class); @@ -497,6 +501,17 @@ public class IndexDiff { } } } + + for (int i = 0; i < treeWalk.getTreeCount(); i++) { + Set values = fileModes.get(treeWalk.getFileMode(i)); + String path = treeWalk.getPathString(); + if (path != null) { + if (values == null) + values = new HashSet(); + values.add(path); + fileModes.put(treeWalk.getFileMode(i), values); + } + } } if (ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL) { @@ -539,6 +554,7 @@ public class IndexDiff { } } } + } // consume the remaining work @@ -675,4 +691,20 @@ public class IndexDiff { final DirCacheEntry entry = dirCache.getEntry(path); return entry != null ? entry.getFileMode() : FileMode.MISSING; } + + /** + * Get the list of paths that IndexDiff has detected to differ and have the + * given file mode + * + * @param mode + * @return the list of paths that IndexDiff has detected to differ and have + * the given file mode + * @since 3.6 + */ + public Set getPathsWithIndexMode(final FileMode mode) { + Set paths = fileModes.get(mode); + if (paths == null) + paths = new HashSet(); + return paths; + } }