Class DirCacheIterator
- Direct Known Subclasses:
DirCacheBuildIterator
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.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
AttributesNode
implementation that provides lazy loading facilities. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final DirCache
The cache this iterator was created to walk.protected DirCacheEntry
The current file entry fromcache
.protected DirCacheTree
The subtree containingcurrentEntry
if this is first entry.private static final byte[]
Byte array holding ".gitattributes" stringprivate int
Next subtree to consider withintree
.protected int
Index of entry withincache
.private final byte[]
Special buffer to hold the ObjectId ofcurrentSubtree
.private final DirCacheTree
The tree this iterator is walking.private final int
Last position in this tree.private final int
First position in this tree.Fields inherited from class org.eclipse.jgit.treewalk.AbstractTreeIterator
attributesNode, DEFAULT_PATH_SIZE, mode, parent, path, pathLen, pathOffset, zeroid
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new iterator for an already loaded DirCache instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
back
(int delta) Move to prior entry, populating this iterator with the entry data.Create a new iterator as though the current entry were a subtree.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?Get the DirCacheEntry for the current file.getEntryAttributesNode
(ObjectReader reader) Retrieves theAttributesNode
for the current entry.boolean
hasId()
Whether the entry has a valid ObjectId.byte[]
idBuffer()
Get the byte array buffer object IDs must be copied out of.int
idOffset()
Get the position withinAbstractTreeIterator.idBuffer()
of this entry's ObjectId.void
next
(int delta) Move to next entry, populating this iterator with the entry data.private void
private void
parseEntry
(boolean forward) void
reset()
Position this iterator on the first entry.Methods inherited from class org.eclipse.jgit.treewalk.AbstractTreeIterator
createSubtreeIterator, ensurePathCapacity, findFile, findFile, getEntryFileMode, getEntryObjectId, getEntryObjectId, getEntryPathBuffer, getEntryPathHashCode, getEntryPathLength, getEntryPathString, getEntryRawMode, getName, getNameLength, getNameOffset, growPath, idEqual, isWorkTree, needsStopWalk, pathCompare, pathCompare, skip, stopWalk, toString
-
Field Details
-
DOT_GIT_ATTRIBUTES_BYTES
private static final byte[] DOT_GIT_ATTRIBUTES_BYTESByte array holding ".gitattributes" string -
cache
The cache this iterator was created to walk. -
tree
The tree this iterator is walking. -
treeStart
private final int treeStartFirst position in this tree. -
treeEnd
private final int treeEndLast position in this tree. -
subtreeId
private final byte[] subtreeIdSpecial buffer to hold the ObjectId ofcurrentSubtree
. -
ptr
protected int ptrIndex of entry withincache
. -
nextSubtreePos
private int nextSubtreePosNext subtree to consider withintree
. -
currentEntry
The current file entry fromcache
. -
currentSubtree
The subtree containingcurrentEntry
if this is first entry.
-
-
Constructor Details
-
DirCacheIterator
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:
dc
- the cache to walk. It must be already loaded into memory.
-
DirCacheIterator
DirCacheIterator(DirCacheIterator p, DirCacheTree dct)
-
-
Method Details
-
createSubtreeIterator
public AbstractTreeIterator createSubtreeIterator(ObjectReader reader) throws IncorrectObjectTypeException, IOException 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 walkingthis
.- Specified by:
createSubtreeIterator
in classAbstractTreeIterator
- 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.IOException
- a loose object or pack file could not be read.
-
createEmptyTreeIterator
Create a new iterator as though the current entry were a subtree.- Overrides:
createEmptyTreeIterator
in classAbstractTreeIterator
- Returns:
- a new empty tree iterator.
-
hasId
public boolean hasId()Whether the entry has a valid ObjectId.- Specified by:
hasId
in classAbstractTreeIterator
- Returns:
true
if the entry has a valid ObjectId.
-
idBuffer
public byte[] idBuffer()Get the byte array buffer object IDs must be copied out of.The 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.
- Specified by:
idBuffer
in classAbstractTreeIterator
- Returns:
- byte array the implementation stores object IDs within.
- See Also:
-
idOffset
public int idOffset()Get the position withinAbstractTreeIterator.idBuffer()
of this entry's ObjectId.- Specified by:
idOffset
in classAbstractTreeIterator
- Returns:
- offset into the array returned by
AbstractTreeIterator.idBuffer()
where the ObjectId must be copied out of.
-
reset
public void reset()Position this iterator on the first entry. The default implementation of this method usesback(1)
untilfirst()
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.- Overrides:
reset
in classAbstractTreeIterator
-
first
public boolean first()Is this tree iterator positioned on its first entry?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()
.- Specified by:
first
in classAbstractTreeIterator
- Returns:
- true if the iterator is positioned on the first entry.
-
eof
public boolean eof()Is this tree iterator at its EOF point (no more entries)?An iterator is at EOF if there is no current entry.
- Specified by:
eof
in classAbstractTreeIterator
- Returns:
- true if we have walked all entries and have none left.
-
next
public void next(int delta) Move to next entry, populating this iterator with the entry data.The 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.mode
AbstractTreeIterator.path
(fromAbstractTreeIterator.pathOffset
toAbstractTreeIterator.pathLen
)AbstractTreeIterator.pathLen
AbstractTreeIterator.idBuffer()
andAbstractTreeIterator.idOffset()
when demanded.- Specified by:
next
in classAbstractTreeIterator
- Parameters:
delta
- number of entries to move the iterator by. Must be a positive, non-zero integer.
-
back
public void back(int delta) Move to prior entry, populating this iterator with the entry data.The 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.mode
AbstractTreeIterator.path
(fromAbstractTreeIterator.pathOffset
toAbstractTreeIterator.pathLen
)AbstractTreeIterator.pathLen
AbstractTreeIterator.idBuffer()
andAbstractTreeIterator.idOffset()
when demanded.- Specified by:
back
in classAbstractTreeIterator
- Parameters:
delta
- number of entries to move the iterator by. Must be a positive, non-zero integer.
-
parseEntry
private void parseEntry() -
parseEntry
private void parseEntry(boolean forward) -
getDirCacheEntry
Get the DirCacheEntry for the current file.- Returns:
- the current cache entry, if this iterator is positioned on a non-tree.
-
getEntryAttributesNode
Retrieves theAttributesNode
for the current entry.- Parameters:
reader
-ObjectReader
used to parse the .gitattributes entry.- Returns:
AttributesNode
for the current entry.- Throws:
IOException
- Since:
- 3.7
-