Browse Source

Merge "Extend IndexDiff to calculate ignored files and folders"

stable-1.2
Christian Halstrick 13 years ago committed by Code Review
parent
commit
a66dea1451
  1. 19
      org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
  2. 22
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/IndexDiffFilter.java

19
org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java

@ -157,6 +157,8 @@ public class IndexDiff {
private Set<String> conflicts = new HashSet<String>(); private Set<String> conflicts = new HashSet<String>();
private Set<String> ignored;
private Set<String> assumeUnchanged; private Set<String> assumeUnchanged;
private DirCache dirCache; private DirCache dirCache;
@ -276,7 +278,8 @@ public class IndexDiff {
if (filter != null) if (filter != null)
filters.add(filter); filters.add(filter);
filters.add(new SkipWorkTreeFilter(INDEX)); filters.add(new SkipWorkTreeFilter(INDEX));
filters.add(new IndexDiffFilter(INDEX, WORKDIR)); IndexDiffFilter indexDiffFilter = new IndexDiffFilter(INDEX, WORKDIR);
filters.add(indexDiffFilter);
treeWalk.setFilter(AndTreeFilter.create(filters)); treeWalk.setFilter(AndTreeFilter.create(filters));
while (treeWalk.next()) { while (treeWalk.next()) {
AbstractTreeIterator treeIterator = treeWalk.getTree(TREE, AbstractTreeIterator treeIterator = treeWalk.getTree(TREE,
@ -340,6 +343,7 @@ public class IndexDiff {
if (monitor != null) if (monitor != null)
monitor.endTask(); monitor.endTask();
ignored = indexDiffFilter.getIgnoredPaths();
if (added.isEmpty() && changed.isEmpty() && removed.isEmpty() if (added.isEmpty() && changed.isEmpty() && removed.isEmpty()
&& missing.isEmpty() && modified.isEmpty() && missing.isEmpty() && modified.isEmpty()
&& untracked.isEmpty()) && untracked.isEmpty())
@ -397,6 +401,19 @@ public class IndexDiff {
return conflicts; return conflicts;
} }
/**
* The method returns the list of ignored files and folders. Only the root
* folder of an ignored folder hierarchy is reported. If a/b/c is listed in
* the .gitignore then you should not expect a/b/c/d/e/f to be reported
* here. Only a/b/c will be reported. Furthermore only ignored files /
* folders are returned that are NOT in the index.
*
* @return list of files / folders that are ignored
*/
public Set<String> getIgnoredNotInIndex() {
return ignored;
}
/** /**
* @return list of files with the flag assume-unchanged * @return list of files with the flag assume-unchanged
*/ */

22
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/IndexDiffFilter.java

@ -43,6 +43,8 @@
package org.eclipse.jgit.treewalk.filter; package org.eclipse.jgit.treewalk.filter;
import java.io.IOException; import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.jgit.dircache.DirCacheIterator; import org.eclipse.jgit.dircache.DirCacheIterator;
import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.errors.IncorrectObjectTypeException;
@ -79,6 +81,8 @@ public class IndexDiffFilter extends TreeFilter {
private final boolean honorIgnores; private final boolean honorIgnores;
private final Set<String> ignoredPaths = new HashSet<String>();
/** /**
* Creates a new instance of this filter. Do not use an instance of this * Creates a new instance of this filter. Do not use an instance of this
* filter in multiple treewalks. * filter in multiple treewalks.
@ -129,8 +133,10 @@ public class IndexDiffFilter extends TreeFilter {
// other tree. // other tree.
final int cnt = tw.getTreeCount(); final int cnt = tw.getTreeCount();
final int dm = tw.getRawMode(dirCache); final int dm = tw.getRawMode(dirCache);
WorkingTreeIterator wi = workingTree(tw);
if (dm == 0) { if (dm == 0) {
if (honorIgnores && workingTree(tw).isEntryIgnored()) { if (honorIgnores && wi.isEntryIgnored()) {
ignoredPaths.add(wi.getEntryPathString());
int i = 0; int i = 0;
for (; i < cnt; i++) { for (; i < cnt; i++) {
if (i == dirCache || i == workingTree) if (i == dirCache || i == workingTree)
@ -166,7 +172,6 @@ public class IndexDiffFilter extends TreeFilter {
// Only one chance left to detect a diff: between index and working // Only one chance left to detect a diff: between index and working
// tree. Make use of the WorkingTreeIterator#isModified() method to // tree. Make use of the WorkingTreeIterator#isModified() method to
// avoid computing SHA1 on filesystem content if not really needed. // avoid computing SHA1 on filesystem content if not really needed.
WorkingTreeIterator wi = workingTree(tw);
DirCacheIterator di = tw.getTree(dirCache, DirCacheIterator.class); DirCacheIterator di = tw.getTree(dirCache, DirCacheIterator.class);
return wi.isModified(di.getDirCacheEntry(), true); return wi.isModified(di.getDirCacheEntry(), true);
} }
@ -191,4 +196,17 @@ public class IndexDiffFilter extends TreeFilter {
public String toString() { public String toString() {
return "INDEX_DIFF_FILTER"; return "INDEX_DIFF_FILTER";
} }
/**
* The method returns the list of ignored files and folders. Only the root
* folder of an ignored folder hierarchy is reported. If a/b/c is listed in
* the .gitignore then you should not expect a/b/c/d/e/f to be reported
* here. Only a/b/c will be reported. Furthermore only ignored files /
* folders are returned that are NOT in the index.
*
* @return ignored paths
*/
public Set<String> getIgnoredPaths() {
return ignoredPaths;
}
} }

Loading…
Cancel
Save