Class IndexDiffFilter

java.lang.Object
org.eclipse.jgit.treewalk.filter.TreeFilter
org.eclipse.jgit.treewalk.filter.IndexDiffFilter

public class IndexDiffFilter extends TreeFilter
A performance optimized variant of TreeFilter.ANY_DIFF which should be used when among the walked trees there is a DirCacheIterator and a WorkingTreeIterator. Please see the documentation of TreeFilter.ANY_DIFF for a basic description of the semantics.

This filter tries to avoid computing content ids of the files in the working-tree. In contrast to TreeFilter.ANY_DIFF this filter takes care to first compare the entry from the DirCacheIterator with the entries from all other iterators besides the WorkingTreeIterator. Since all those entries have fast access to content ids that is very fast. If a difference is detected in this step this filter decides to include that path before even looking at the working-tree entry.

If no difference is found then we have to compare index and working-tree as the last step. By making use of WorkingTreeIterator.isModified(org.eclipse.jgit.dircache.DirCacheEntry, boolean, ObjectReader) we can avoid the computation of the content id if the file is not dirty.

Instances of this filter should not be used for multiple TreeWalks. Always construct a new instance of this filter for each TreeWalk.

  • Field Details

    • dirCache

      private final int dirCache
    • workingTree

      private final int workingTree
    • honorIgnores

      private final boolean honorIgnores
    • ignoredPaths

      private final Set<String> ignoredPaths
    • untrackedParentFolders

      private final LinkedList<String> untrackedParentFolders
    • untrackedFolders

      private final LinkedList<String> untrackedFolders
  • Constructor Details

    • IndexDiffFilter

      public IndexDiffFilter(int dirCacheIndex, int workingTreeIndex)
      Creates a new instance of this filter. Do not use an instance of this filter in multiple treewalks.
      Parameters:
      dirCacheIndex - the index of the DirCacheIterator in the associated treewalk
      workingTreeIndex - the index of the WorkingTreeIterator in the associated treewalk
    • IndexDiffFilter

      public IndexDiffFilter(int dirCacheIndex, int workingTreeIndex, boolean honorIgnores)
      Creates a new instance of this filter. Do not use an instance of this filter in multiple treewalks.
      Parameters:
      dirCacheIndex - the index of the DirCacheIterator in the associated treewalk
      workingTreeIndex - the index of the WorkingTreeIterator in the associated treewalk
      honorIgnores - true if the filter should skip working tree files that are declared as ignored by the standard exclude mechanisms.
  • Method Details

    • include

      Determine if the current entry is interesting to report.

      This method is consulted for subtree entries even if TreeWalk.isRecursive() is enabled. The consultation allows the filter to bypass subtree recursion on a case-by-case basis, even when recursion is enabled at the application level.

      Specified by:
      include in class TreeFilter
      Parameters:
      tw - the walker the filter needs to examine.
      Returns:
      true if the current entry should be seen by the application; false to hide the entry.
      Throws:
      MissingObjectException - an object the filter needs to consult to determine its answer does not exist in the Git repository the walker is operating on. Filtering this current walker entry is impossible without the object.
      IncorrectObjectTypeException - an object the filter needed to consult was not of the expected object type. This usually indicates a corrupt repository, as an object link is referencing the wrong type.
      IOException - a loose object or pack file could not be read to obtain data necessary for the filter to make its decision.
    • copyUntrackedFolders

      private void copyUntrackedFolders(String currentPath)
      Copy all entries which are still in untrackedParentFolders and which belong to a path this treewalk has left into untrackedFolders. It is sure that we will not find any tracked files underneath these paths. Therefore these paths definitely belong to untracked folders.
      Parameters:
      currentPath - the current path of the treewalk
    • workingTree

      private WorkingTreeIterator workingTree(TreeWalk tw)
    • shouldBeRecursive

      public boolean shouldBeRecursive()
      Does this tree filter require a recursive walk to match everything?

      If this tree filter is matching on full entry path names and its pattern is looking for a '/' then the filter would require a recursive TreeWalk to accurately make its decisions. The walker is not required to enable recursive behavior for any particular filter, this is only a hint.

      Specified by:
      shouldBeRecursive in class TreeFilter
      Returns:
      true if the filter would like to have the walker recurse into subtrees to make sure it matches everything correctly; false if the filter does not require entering subtrees.
    • clone

      public TreeFilter clone()
      Clone this tree filter, including its parameters.

      This is a deep clone. If this filter embeds objects or other filters it must also clone those, to ensure the instances do not share mutable data.

      Specified by:
      clone in class TreeFilter
    • toString

      public String toString()
      Overrides:
      toString in class TreeFilter
    • getIgnoredPaths

      public Set<String> getIgnoredPaths()
      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.
      Returns:
      ignored paths
    • getUntrackedFolders

      public List<String> getUntrackedFolders()

      Getter for the field untrackedFolders.

      Returns:
      all paths of folders which contain only untracked files/folders. If on the associated treewalk postorder traversal was turned on (see TreeWalk.setPostOrderTraversal(boolean)) then an empty list will be returned.