Extend IndexDiff to calculate ignored files and folders

IndexDiff was extended to calculate ignored files and folders.
The calculation only considers files that are NOT in the index.
This functionality is required by the new EGit decorator implementation.

Bug: 359264
Change-Id: I8f09d6a4d61b64aeea80fd22bf3a2963c2bca347
Signed-off-by: Jens Baumgart <jens.baumgart@sap.com>
This commit is contained in:
Jens Baumgart 2011-10-05 13:56:23 +02:00
parent 602c869d7a
commit 6befabcb15
2 changed files with 38 additions and 3 deletions

View File

@ -157,6 +157,8 @@ public TreeFilter clone() {
private Set<String> conflicts = new HashSet<String>();
private Set<String> ignored;
private Set<String> assumeUnchanged;
private DirCache dirCache;
@ -276,7 +278,8 @@ public boolean diff(final ProgressMonitor monitor, int estWorkTreeSize,
if (filter != null)
filters.add(filter);
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));
while (treeWalk.next()) {
AbstractTreeIterator treeIterator = treeWalk.getTree(TREE,
@ -340,6 +343,7 @@ public boolean diff(final ProgressMonitor monitor, int estWorkTreeSize,
if (monitor != null)
monitor.endTask();
ignored = indexDiffFilter.getIgnoredPaths();
if (added.isEmpty() && changed.isEmpty() && removed.isEmpty()
&& missing.isEmpty() && modified.isEmpty()
&& untracked.isEmpty())
@ -397,6 +401,19 @@ public Set<String> getConflicting() {
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
*/

View File

@ -43,6 +43,8 @@
package org.eclipse.jgit.treewalk.filter;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.jgit.dircache.DirCacheIterator;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
@ -79,6 +81,8 @@ public class IndexDiffFilter extends TreeFilter {
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
* filter in multiple treewalks.
@ -129,8 +133,10 @@ public boolean include(TreeWalk tw) throws MissingObjectException,
// other tree.
final int cnt = tw.getTreeCount();
final int dm = tw.getRawMode(dirCache);
WorkingTreeIterator wi = workingTree(tw);
if (dm == 0) {
if (honorIgnores && workingTree(tw).isEntryIgnored()) {
if (honorIgnores && wi.isEntryIgnored()) {
ignoredPaths.add(wi.getEntryPathString());
int i = 0;
for (; i < cnt; i++) {
if (i == dirCache || i == workingTree)
@ -166,7 +172,6 @@ public boolean include(TreeWalk tw) throws MissingObjectException,
// Only one chance left to detect a diff: between index and working
// tree. Make use of the WorkingTreeIterator#isModified() method to
// avoid computing SHA1 on filesystem content if not really needed.
WorkingTreeIterator wi = workingTree(tw);
DirCacheIterator di = tw.getTree(dirCache, DirCacheIterator.class);
return wi.isModified(di.getDirCacheEntry(), true);
}
@ -191,4 +196,17 @@ public TreeFilter clone() {
public String toString() {
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;
}
}