diff options
author | Jens Baumgart <jens.baumgart@sap.com> | 2011-10-05 13:56:23 +0200 |
---|---|---|
committer | Jens Baumgart <jens.baumgart@sap.com> | 2011-10-05 13:56:23 +0200 |
commit | 6befabcb1584118fb02188f602f7ca34b9a7efc5 (patch) | |
tree | d54b5c07be06a10adceeba184f64128d770978aa /org.eclipse.jgit/src | |
parent | 602c869d7a2b75f092ef96ab04fe1865ff317d5b (diff) | |
download | jgit-6befabcb1584118fb02188f602f7ca34b9a7efc5.tar.gz jgit-6befabcb1584118fb02188f602f7ca34b9a7efc5.zip |
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>
Diffstat (limited to 'org.eclipse.jgit/src')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java | 19 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/IndexDiffFilter.java | 22 |
2 files changed, 38 insertions, 3 deletions
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 5d121dd92b..af64f20943 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java +++ b/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> ignored; + private Set<String> assumeUnchanged; private DirCache dirCache; @@ -276,7 +278,8 @@ public class IndexDiff { 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 class IndexDiff { if (monitor != null) monitor.endTask(); + ignored = indexDiffFilter.getIgnoredPaths(); if (added.isEmpty() && changed.isEmpty() && removed.isEmpty() && missing.isEmpty() && modified.isEmpty() && untracked.isEmpty()) @@ -398,6 +402,19 @@ public class IndexDiff { } /** + * 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 */ public Set<String> getAssumeUnchanged() { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/IndexDiffFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/IndexDiffFilter.java index 8499970ba8..2f8608ee47 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/IndexDiffFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/IndexDiffFilter.java @@ -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 class IndexDiffFilter extends TreeFilter { // 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 class IndexDiffFilter extends TreeFilter { // 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 class IndexDiffFilter extends TreeFilter { 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; + } } |