]> source.dussan.org Git - jgit.git/commitdiff
Extend IndexDiff to calculate ignored files and folders 20/4320/4
authorJens Baumgart <jens.baumgart@sap.com>
Wed, 5 Oct 2011 11:56:23 +0000 (13:56 +0200)
committerJens Baumgart <jens.baumgart@sap.com>
Wed, 5 Oct 2011 11:56:23 +0000 (13:56 +0200)
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>
org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/IndexDiffFilter.java

index 5d121dd92b84546a17e86d18e7aebb23854c0e35..af64f20943000fba9487ae11abd4247bcc0f5088 100644 (file)
@@ -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())
@@ -397,6 +401,19 @@ public class IndexDiff {
                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
         */
index 8499970ba877029f279621b45a794a54d86607cb..2f8608ee47ed7c93e416c2efe642625c614f9db9 100644 (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 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;
+       }
 }