public class DirCacheIterator extends AbstractTreeIterator
DirCache as part of a TreeWalk.
This is an iterator to adapt a loaded DirCache instance (such as
read from an existing .git/index file) to the tree structure
used by a TreeWalk, making it possible for applications to walk
over any combination of tree objects already in the object database, index
files, or working directories.
TreeWalk| Modifier and Type | Field and Description |
|---|---|
protected DirCache |
cache
The cache this iterator was created to walk.
|
protected DirCacheEntry |
currentEntry
The current file entry from
cache. |
protected DirCacheTree |
currentSubtree
The subtree containing
currentEntry if this is first entry. |
protected int |
ptr
Index of entry within
cache. |
DEFAULT_PATH_SIZE, mode, path, pathLen, pathOffset, zeroid| Constructor and Description |
|---|
DirCacheIterator(DirCache dc)
Create a new iterator for an already loaded DirCache instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
back(int delta)
Move to prior entry, populating this iterator with the entry data.
|
EmptyTreeIterator |
createEmptyTreeIterator()
Create a new iterator as though the current entry were a subtree.
|
AbstractTreeIterator |
createSubtreeIterator(ObjectReader reader)
Create a new iterator for the current entry's subtree.
|
boolean |
eof()
Is this tree iterator at its EOF point (no more entries)?
|
boolean |
first()
Is this tree iterator positioned on its first entry?
|
DirCacheEntry |
getDirCacheEntry()
Get the DirCacheEntry for the current file.
|
boolean |
hasId() |
byte[] |
idBuffer()
Get the byte array buffer object IDs must be copied out of.
|
int |
idOffset()
Get the position within
AbstractTreeIterator.idBuffer() of this entry's ObjectId. |
void |
next(int delta)
Move to next entry, populating this iterator with the entry data.
|
void |
reset()
Position this iterator on the first entry.
|
createSubtreeIterator, ensurePathCapacity, getEntryFileMode, getEntryObjectId, getEntryObjectId, getEntryPathBuffer, getEntryPathHashCode, getEntryPathLength, getEntryPathString, getEntryRawMode, getName, getNameLength, getNameOffset, growPath, idEqual, pathCompare, pathCompare, skip, stopWalk, toStringprotected final DirCache cache
protected int ptr
cache.protected DirCacheEntry currentEntry
cache.protected DirCacheTree currentSubtree
currentEntry if this is first entry.public DirCacheIterator(DirCache dc)
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.
dc - the cache to walk. It must be already loaded into memory.public AbstractTreeIterator createSubtreeIterator(ObjectReader reader) throws IncorrectObjectTypeException, IOException
AbstractTreeIterator
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.
createSubtreeIterator in class AbstractTreeIteratorreader - reader to load the tree data from.IncorrectObjectTypeException - the current entry is not actually a tree and cannot be parsed
as though it were a tree.IOException - a loose object or pack file could not be read.public EmptyTreeIterator createEmptyTreeIterator()
AbstractTreeIteratorcreateEmptyTreeIterator in class AbstractTreeIteratorpublic boolean hasId()
hasId in class AbstractTreeIteratorpublic byte[] idBuffer()
AbstractTreeIteratorThe id buffer contains the bytes necessary to construct an ObjectId for the current entry of this iterator. The buffer can be the same buffer for all entries, or it can be a unique buffer per-entry. Implementations are encouraged to expose their private buffer whenever possible to reduce garbage generation and copying costs.
idBuffer in class AbstractTreeIteratorAbstractTreeIterator.getEntryObjectId()public int idOffset()
AbstractTreeIteratorAbstractTreeIterator.idBuffer() of this entry's ObjectId.idOffset in class AbstractTreeIteratorAbstractTreeIterator.idBuffer() where the
ObjectId must be copied out of.public void reset()
AbstractTreeIteratorback(1) until
first() is true. This is most likely not the most efficient
method of repositioning the iterator to its first entry, so subclasses
are strongly encouraged to override the method.reset in class AbstractTreeIteratorpublic boolean first()
AbstractTreeIterator
An iterator is positioned on the first entry if back(1)
would be an invalid request as there is no entry before the current one.
An empty iterator (one with no entries) will be
first() && eof().
first in class AbstractTreeIteratorpublic boolean eof()
AbstractTreeIteratorAn iterator is at EOF if there is no current entry.
eof in class AbstractTreeIteratorpublic void next(int delta)
AbstractTreeIteratorThe delta indicates how many moves forward should occur. The most common delta is 1 to move to the next entry.
Implementations must populate the following members:
AbstractTreeIterator.modeAbstractTreeIterator.path (from AbstractTreeIterator.pathOffset to AbstractTreeIterator.pathLen)AbstractTreeIterator.pathLenAbstractTreeIterator.idBuffer() and AbstractTreeIterator.idOffset()
when demanded.next in class AbstractTreeIteratordelta - number of entries to move the iterator by. Must be a positive,
non-zero integer.public void back(int delta)
AbstractTreeIteratorThe delta indicates how many moves backward should occur.The most common delta is 1 to move to the prior entry.
Implementations must populate the following members:
AbstractTreeIterator.modeAbstractTreeIterator.path (from AbstractTreeIterator.pathOffset to AbstractTreeIterator.pathLen)AbstractTreeIterator.pathLenAbstractTreeIterator.idBuffer() and AbstractTreeIterator.idOffset()
when demanded.back in class AbstractTreeIteratordelta - number of entries to move the iterator by. Must be a positive,
non-zero integer.public DirCacheEntry getDirCacheEntry()
Copyright © 2014. All rights reserved.