]> source.dussan.org Git - jgit.git/commitdiff
Add toString and improve Javadoc of NotIgnoredFilter 95/1495/1
authorShawn O. Pearce <spearce@spearce.org>
Wed, 1 Sep 2010 22:22:48 +0000 (15:22 -0700)
committerShawn O. Pearce <spearce@spearce.org>
Wed, 1 Sep 2010 22:24:32 +0000 (15:24 -0700)
Today while debugging some TreeWalk related code I noticed this
filter did not have a toString(), making it harder to see what the
filter graph was at a glance in the debugger.  Add a toString()
for debugging to match other TreeFilters, and clean up the Javadoc
slightly so its a bit more clear about the purpose of the filter.

While we are mucking about with some of this code, simplify
the logic of include so its shorter and thus faster to read.
The pattern now more closely matches that of SkipWorkTreeFilter.

Change-Id: Iad433a1fa6b395dc1acb455aca268b9ce2f1d41b
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/NotIgnoredFilter.java

index 122ce40344ecab2872dd9eb2aef544437b6d9bb7..2e96d2ffa460f5a32c873d1630515cbe180e7f1a 100644 (file)
@@ -50,32 +50,26 @@ import org.eclipse.jgit.treewalk.TreeWalk;
 import org.eclipse.jgit.treewalk.WorkingTreeIterator;
 
 /**
- * This filter includes workdir entries that are not ignored. This class is
- * immutable.
+ * Skip {@link WorkingTreeIterator} entries that appear in gitignore files.
  */
 public class NotIgnoredFilter extends TreeFilter {
-
-       private final int workdirTreeIndex;
+       private final int index;
 
        /**
-        * constructor
+        * Construct a filter to ignore paths known to a particular iterator.
         *
         * @param workdirTreeIndex
         *            index of the workdir tree in the tree walk
         */
        public NotIgnoredFilter(final int workdirTreeIndex) {
-               this.workdirTreeIndex = workdirTreeIndex;
+               this.index = workdirTreeIndex;
        }
 
        @Override
-       public boolean include(TreeWalk walker) throws MissingObjectException,
+       public boolean include(TreeWalk tw) throws MissingObjectException,
                        IncorrectObjectTypeException, IOException {
-               WorkingTreeIterator workingTreeIterator = walker.getTree(
-                               workdirTreeIndex, WorkingTreeIterator.class);
-               if (workingTreeIterator != null)
-                       // do not include ignored entries
-                       return !workingTreeIterator.isEntryIgnored();
-               return true;
+               WorkingTreeIterator i = tw.getTree(index, WorkingTreeIterator.class);
+               return i == null || !i.isEntryIgnored();
        }
 
        @Override
@@ -89,4 +83,8 @@ public class NotIgnoredFilter extends TreeFilter {
                return this;
        }
 
+       @Override
+       public String toString() {
+               return "NotIgnored(" + index + ")";
+       }
 }