Class DirCacheBuildIterator


  • public class DirCacheBuildIterator
    extends DirCacheIterator
    Iterate and update a DirCache as part of a TreeWalk.

    Like DirCacheIterator this iterator allows a DirCache to be used in parallel with other sorts of iterators in a TreeWalk. However any entry which appears in the source DirCache and which is skipped by the TreeFilter is automatically copied into DirCacheBuilder, thus retaining it in the newly updated index.

    This iterator is suitable for update processes, or even a simple delete algorithm. For example deleting a path:

     final DirCache dirc = db.lockDirCache();
     final DirCacheBuilder edit = dirc.builder();
    
     final TreeWalk walk = new TreeWalk(db);
     walk.reset();
     walk.setRecursive(true);
     walk.setFilter(PathFilter.create("name/to/remove"));
     walk.addTree(new DirCacheBuildIterator(edit));
    
     while (walk.next())
            ; // do nothing on a match as we want to remove matches
     edit.commit();
     
    • Constructor Detail

      • DirCacheBuildIterator

        public DirCacheBuildIterator​(DirCacheBuilder dcb)
        Create a new iterator for an already loaded DirCache instance.

        The iterator implementation may copy part of the cache's data during construction, so the cache must be read in prior to creating the iterator.

        Parameters:
        dcb - the cache builder for the cache to walk. The cache must be already loaded into memory.
    • Method Detail

      • createSubtreeIterator

        public AbstractTreeIterator createSubtreeIterator​(ObjectReader reader)
                                                   throws IncorrectObjectTypeException,
                                                          java.io.IOException
        Description copied from class: AbstractTreeIterator
        Create a new iterator for the current entry's subtree.

        The parent reference of the iterator must be this, otherwise the caller would not be able to exit out of the subtree iterator correctly and return to continue walking this.

        Overrides:
        createSubtreeIterator in class DirCacheIterator
        Parameters:
        reader - reader to load the tree data from.
        Returns:
        a new parser that walks over the current subtree.
        Throws:
        IncorrectObjectTypeException - the current entry is not actually a tree and cannot be parsed as though it were a tree.
        java.io.IOException - a loose object or pack file could not be read.
      • stopWalk

        public void stopWalk()
        Description copied from class: AbstractTreeIterator
        Indicates to the iterator that no more entries will be read.

        This is only invoked by TreeWalk when the iteration is aborted early due to a StopWalkException being thrown from within a TreeFilter.

        Overrides:
        stopWalk in class AbstractTreeIterator