Top Description Inners Fields Constructors Methods
org.eclipse.jgit.dircache

public Class DirCacheIterator

extends AbstractTreeIterator
Class Inheritance
Known Direct Subclasses
org.eclipse.jgit.dircache.DirCacheBuildIterator
Static Imports
java.nio.charset.StandardCharsets.UTF_8

Iterate a org.eclipse.jgit.dircache.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
org.eclipse.jgit.treewalk.TreeWalk

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
DirCacheIterator.LazyLoadingAttributesNode

AttributesNode implementation that provides lazy loading facilities.

Field Summary

Modifier and TypeField and Description
protected final 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.

private static final byte[]
DOT_GIT_ATTRIBUTES_BYTES

Byte array holding ".gitattributes" string

private int
nextSubtreePos

Next subtree to consider within tree.

protected int
ptr

Index of entry within cache.

private final byte[]
subtreeId

Special buffer to hold the ObjectId of currentSubtree.

private final DirCacheTree
tree

The tree this iterator is walking.

private final int
treeEnd

Last position in this tree.

private final int
treeStart

First position in this tree.

Inherited from org.eclipse.jgit.treewalk.AbstractTreeIterator:
attributesNodeDEFAULT_PATH_SIZEmodeparentpathpathLenpathOffsetzeroid

Constructor Summary

AccessConstructor and Description
public
DirCacheIterator(DirCache
the cache to walk. It must be already loaded into memory.
dc
)

Create a new iterator for an already loaded DirCache instance.

pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
back(int
number of entries to move the iterator by. Must be a positive, non-zero integer.
delta
)

Implements abstract org.eclipse.jgit.treewalk.AbstractTreeIterator.back.

Move to prior entry, populating this iterator with the entry data.

public EmptyTreeIterator
createEmptyTreeIterator()

Overrides org.eclipse.jgit.treewalk.AbstractTreeIterator.createEmptyTreeIterator.

Create a new iterator as though the current entry were a subtree.

public AbstractTreeIterator
createSubtreeIterator(ObjectReader
reader to load the tree data from.
reader
)

Implements abstract org.eclipse.jgit.treewalk.AbstractTreeIterator.createSubtreeIterator.

Create a new iterator for the current entry's subtree.

public boolean
eof()

Implements abstract org.eclipse.jgit.treewalk.AbstractTreeIterator.eof.

Is this tree iterator at its EOF point (no more entries)?

public boolean
first()

Implements abstract org.eclipse.jgit.treewalk.AbstractTreeIterator.first.

Is this tree iterator positioned on its first entry?

public DirCacheEntry

Returns:

the current cache entry, if this iterator is positioned on a non-tree.
getDirCacheEntry
()

Get the DirCacheEntry for the current file.

public AttributesNode

Returns:

org.eclipse.jgit.attributes.AttributesNode for the current entry.
getEntryAttributesNode
(ObjectReader
org.eclipse.jgit.lib.ObjectReader used to parse the .gitattributes entry.
reader
)

Retrieves the org.eclipse.jgit.attributes.AttributesNode for the current entry.

public boolean
hasId()

Implements abstract org.eclipse.jgit.treewalk.AbstractTreeIterator.hasId.

Whether the entry has a valid ObjectId.

public byte[]
idBuffer()

Implements abstract org.eclipse.jgit.treewalk.AbstractTreeIterator.idBuffer.

Get the byte array buffer object IDs must be copied out of.

public int
idOffset()

Implements abstract org.eclipse.jgit.treewalk.AbstractTreeIterator.idOffset.

Get the position within idBuffer() of this entry's ObjectId.

public void
next(int
number of entries to move the iterator by. Must be a positive, non-zero integer.
delta
)

Implements abstract org.eclipse.jgit.treewalk.AbstractTreeIterator.next.

Move to next entry, populating this iterator with the entry data.

private void
private void
parseEntry(boolean forward)

public void
reset()

Overrides org.eclipse.jgit.treewalk.AbstractTreeIterator.reset.

Position this iterator on the first entry.

Inherited from org.eclipse.jgit.treewalk.AbstractTreeIterator:
createSubtreeIteratorensurePathCapacityfindFilefindFilegetEntryFileModegetEntryObjectIdgetEntryObjectIdgetEntryPathBuffergetEntryPathHashCodegetEntryPathLengthgetEntryPathStringgetEntryRawModegetNamegetNameLengthgetNameOffsetgrowPathidEqualisWorkTreeneedsStopWalkpathComparepathCompareskipstopWalktoString

Field Detail

cacheback to summary
protected final DirCache cache

The cache this iterator was created to walk.

currentEntryback to summary
protected DirCacheEntry currentEntry

The current file entry from cache.

currentSubtreeback to summary
protected DirCacheTree currentSubtree

The subtree containing currentEntry if this is first entry.

DOT_GIT_ATTRIBUTES_BYTESback to summary
private static final byte[] DOT_GIT_ATTRIBUTES_BYTES

Byte array holding ".gitattributes" string

nextSubtreePosback to summary
private int nextSubtreePos

Next subtree to consider within tree.

ptrback to summary
protected int ptr

Index of entry within cache.

subtreeIdback to summary
private final byte[] subtreeId

Special buffer to hold the ObjectId of currentSubtree.

treeback to summary
private final DirCacheTree tree

The tree this iterator is walking.

treeEndback to summary
private final int treeEnd

Last position in this tree.

treeStartback to summary
private final int treeStart

First position in this tree.

Constructor Detail

DirCacheIteratorback to summary
public DirCacheIterator(DirCache dc)

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:DirCache

the cache to walk. It must be already loaded into memory.

DirCacheIteratorback to summary
pack-priv DirCacheIterator(DirCacheIterator p, DirCacheTree dct)

Method Detail

backback to summary
public void back(int delta)

Implements abstract org.eclipse.jgit.treewalk.AbstractTreeIterator.back.

Doc from org.eclipse.jgit.treewalk.AbstractTreeIterator.back.

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:

as well as any implementation dependent information necessary to accurately return data from idBuffer() and idOffset() when demanded.
Parameters
delta:int

number of entries to move the iterator by. Must be a positive, non-zero integer.

Annotations
@Override
createEmptyTreeIteratorback to summary
public EmptyTreeIterator createEmptyTreeIterator()

Overrides org.eclipse.jgit.treewalk.AbstractTreeIterator.createEmptyTreeIterator.

Doc from org.eclipse.jgit.treewalk.AbstractTreeIterator.createEmptyTreeIterator.

Create a new iterator as though the current entry were a subtree.

Returns:EmptyTreeIterator

a new empty tree iterator.

Annotations
@Override
createSubtreeIteratorback to summary
public AbstractTreeIterator createSubtreeIterator(ObjectReader reader) throws IncorrectObjectTypeException, IOException

Implements abstract org.eclipse.jgit.treewalk.AbstractTreeIterator.createSubtreeIterator.

Doc from org.eclipse.jgit.treewalk.AbstractTreeIterator.createSubtreeIterator.

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.

Parameters
reader:ObjectReader

reader to load the tree data from.

Returns:AbstractTreeIterator

a new parser that walks over the current subtree.

Annotations
@Override
Exceptions
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.
eofback to summary
public boolean eof()

Implements abstract org.eclipse.jgit.treewalk.AbstractTreeIterator.eof.

Doc from org.eclipse.jgit.treewalk.AbstractTreeIterator.eof.

Is this tree iterator at its EOF point (no more entries)?

An iterator is at EOF if there is no current entry.

Returns:boolean

true if we have walked all entries and have none left.

Annotations
@Override
firstback to summary
public boolean first()

Implements abstract org.eclipse.jgit.treewalk.AbstractTreeIterator.first.

Doc from org.eclipse.jgit.treewalk.AbstractTreeIterator.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().

Returns:boolean

true if the iterator is positioned on the first entry.

Annotations
@Override
getDirCacheEntryback to summary
public DirCacheEntry getDirCacheEntry()

Get the DirCacheEntry for the current file.

Returns:DirCacheEntry

the current cache entry, if this iterator is positioned on a non-tree.

getEntryAttributesNodeback to summary
public AttributesNode getEntryAttributesNode(ObjectReader reader) throws IOException

Retrieves the org.eclipse.jgit.attributes.AttributesNode for the current entry.

Parameters
reader:ObjectReader

org.eclipse.jgit.lib.ObjectReader used to parse the .gitattributes entry.

Returns:AttributesNode

org.eclipse.jgit.attributes.AttributesNode for the current entry.

Exceptions
IOException:
if an IO error occurred
Since
3.7
hasIdback to summary
public boolean hasId()

Implements abstract org.eclipse.jgit.treewalk.AbstractTreeIterator.hasId.

Doc from org.eclipse.jgit.treewalk.AbstractTreeIterator.hasId.

Whether the entry has a valid ObjectId.

Returns:boolean

true if the entry has a valid ObjectId.

Annotations
@Override
idBufferback to summary
public byte[] idBuffer()

Implements abstract org.eclipse.jgit.treewalk.AbstractTreeIterator.idBuffer.

Doc from org.eclipse.jgit.treewalk.AbstractTreeIterator.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.

Returns:byte[]

byte array the implementation stores object IDs within.

Annotations
@Override
idOffsetback to summary
public int idOffset()

Implements abstract org.eclipse.jgit.treewalk.AbstractTreeIterator.idOffset.

Doc from org.eclipse.jgit.treewalk.AbstractTreeIterator.idOffset.

Get the position within idBuffer() of this entry's ObjectId.

Returns:int

offset into the array returned by idBuffer() where the ObjectId must be copied out of.

Annotations
@Override
nextback to summary
public void next(int delta)

Implements abstract org.eclipse.jgit.treewalk.AbstractTreeIterator.next.

Doc from org.eclipse.jgit.treewalk.AbstractTreeIterator.next.

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:

as well as any implementation dependent information necessary to accurately return data from idBuffer() and idOffset() when demanded.
Parameters
delta:int

number of entries to move the iterator by. Must be a positive, non-zero integer.

Annotations
@Override
parseEntryback to summary
private void parseEntry()
parseEntryback to summary
private void parseEntry(boolean forward)
resetback to summary
public void reset()

Overrides org.eclipse.jgit.treewalk.AbstractTreeIterator.reset.

Doc from org.eclipse.jgit.treewalk.AbstractTreeIterator.reset.

Position this iterator on the first entry. The default implementation of this method uses back(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.

Annotations
@Override
org.eclipse.jgit.dircache back to summary

private Class DirCacheIterator.LazyLoadingAttributesNode

extends AttributesNode
Class Inheritance

AttributesNode implementation that provides lazy loading facilities.

Field Summary

Modifier and TypeField and Description
pack-priv final ObjectId

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv AttributesNode
Inherited from org.eclipse.jgit.attributes.AttributesNode:
getRulesparse

Field Detail

objectIdback to summary
pack-priv final ObjectId objectId

Constructor Detail

LazyLoadingAttributesNodeback to summary
pack-priv LazyLoadingAttributesNode(ObjectId objectId)

Method Detail

loadback to summary
pack-priv AttributesNode load(ObjectReader reader) throws IOException