Top Description Fields Constructors Methods
org.eclipse.jgit.treewalk

public Class CanonicalTreeParser

extends AbstractTreeIterator
Class Inheritance
Known Direct Subclasses
org.eclipse.jgit.notes.NoteParser
Static Imports
org.eclipse.jgit.lib.Constants.DOT_GIT_ATTRIBUTES, .Constants.OBJECT_ID_LENGTH, .Constants.OBJ_BLOB, .Constants.OBJ_TREE, .Constants.TYPE_TREE, .Constants.encode

Parses raw Git trees from the canonical semi-text/semi-binary format.

Field Summary

Modifier and TypeField and Description
private static final byte[]
private int
currPtr

First offset within raw of the current entry's data.

private static final byte[]
private int
nextPtr

Offset one past the current entry (first byte of next entry).

private int
prevPtr

First offset within raw of the prior entry.

private byte[]
Inherited from org.eclipse.jgit.treewalk.AbstractTreeIterator:
attributesNodeDEFAULT_PATH_SIZEmatchesmatchShiftmodeparentpathpathLenpathOffsetzeroid

Constructor Summary

AccessConstructor and Description
public
CanonicalTreeParser()

Create a new parser.

public
CanonicalTreeParser(final byte[]
position of this iterator in the repository tree. The value may be null or the empty array to indicate the prefix is the root of the repository. A trailing slash ('/') is automatically appended if the prefix does not end in '/'.
prefix
,
final ObjectReader
reader to load the tree data from.
reader
,
final AnyObjectId
identity of the tree being parsed; used only in exception messages if data corruption is found.
treeId
)

Create a new parser for a tree appearing in a subset of a repository.

private

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 CanonicalTreeParser
createSubtreeIterator(final ObjectReader
reader to load the tree data from.
reader
,
final MutableObjectId
temporary ObjectId buffer for use by this method.
idBuffer
)

Overrides org.eclipse.jgit.treewalk.AbstractTreeIterator.createSubtreeIterator.

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

public CanonicalTreeParser
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 final CanonicalTreeParser

Returns:

a new parser that walks over the current subtree.
createSubtreeIterator0
(final ObjectReader
reader to load the tree data from.
reader
,
final AnyObjectId
ObjectId of the tree to open.
id
)

Back door to quickly create a subtree iterator for any subtree.

public boolean
eof()

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

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

private AttributesNode
public boolean
first()

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

Is this tree iterator positioned on its first entry?

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
)

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

public CanonicalTreeParser

Returns:

the parent of this tree parser.
getParent
()
Deprecated internal use only

Get the parent of this tree parser.

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.

private static AttributesNode
public CanonicalTreeParser

Returns:

this iterator, or its parent, if the tree is at eof.
next
()

Get this iterator, or its parent, if the tree is at eof.

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 static AttributesNode
private void
public void
reset(byte[]
the raw tree content.
treeData
)

Reset this parser to walk through the given tree data.

public void
reset(ObjectReader
reader to use during repository access.
reader
,
AnyObjectId
identity of the tree being parsed; used only in exception messages if data corruption is found.
id
)

Reset this parser to walk through the given tree.

public void
reset()

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

Position this iterator on the first entry.

public CanonicalTreeParser

Returns:

the root level parser.
resetRoot
(final ObjectReader
reader to use during repository access.
reader
,
final AnyObjectId
identity of the tree being parsed; used only in exception messages if data corruption is found.
id
)

Reset this parser to walk through the given tree.

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

Field Detail

ATTRSback to summary
private static final byte[] ATTRS
currPtrback to summary
private int currPtr

First offset within raw of the current entry's data.

EMPTYback to summary
private static final byte[] EMPTY
nextPtrback to summary
private int nextPtr

Offset one past the current entry (first byte of next entry).

prevPtrback to summary
private int prevPtr

First offset within raw of the prior entry.

rawback to summary
private byte[] raw

Constructor Detail

CanonicalTreeParserback to summary
public CanonicalTreeParser()

Create a new parser.

CanonicalTreeParserback to summary
public CanonicalTreeParser(final byte[] prefix, final ObjectReader reader, final AnyObjectId treeId) throws IncorrectObjectTypeException, IOException

Create a new parser for a tree appearing in a subset of a repository.

Parameters
prefix:byte[]

position of this iterator in the repository tree. The value may be null or the empty array to indicate the prefix is the root of the repository. A trailing slash ('/') is automatically appended if the prefix does not end in '/'.

reader:ObjectReader

reader to load the tree data from.

treeId:AnyObjectId

identity of the tree being parsed; used only in exception messages if data corruption is found.

Exceptions
IncorrectObjectTypeException:
the object supplied as an argument 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.
MissingObjectException:
the object supplied is not available from the repository.
CanonicalTreeParserback to summary
private CanonicalTreeParser(CanonicalTreeParser p)

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
createSubtreeIteratorback to summary
public CanonicalTreeParser createSubtreeIterator(final ObjectReader reader, final MutableObjectId idBuffer) throws IncorrectObjectTypeException, IOException

Overrides 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.

idBuffer:MutableObjectId

temporary ObjectId buffer for use by this method.

Returns:CanonicalTreeParser

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.
createSubtreeIteratorback to summary
public CanonicalTreeParser 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:CanonicalTreeParser

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.
createSubtreeIterator0back to summary
public final CanonicalTreeParser createSubtreeIterator0(final ObjectReader reader, final AnyObjectId id) throws IOException

Back door to quickly create a subtree iterator for any subtree.

Don't use this unless you are ObjectWalk. The method is meant to be called only once the current entry has been identified as a tree and its identity has been converted into an ObjectId.

Parameters
reader:ObjectReader

reader to load the tree data from.

id:AnyObjectId

ObjectId of the tree to open.

Returns:CanonicalTreeParser

a new parser that walks over the current subtree.

Exceptions
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
findAttributesback to summary
private AttributesNode findAttributes(ObjectReader reader) throws IOException
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
getEntryAttributesNodeback to summary
public AttributesNode getEntryAttributesNode(ObjectReader reader) throws IOException

Retrieve 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
4.2
getParentback to summary
public CanonicalTreeParser getParent()

Deprecated

internal use only

Get the parent of this tree parser.

Returns:CanonicalTreeParser

the parent of this tree parser.

Annotations
@Deprecated
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
loadAttributesback to summary
private static AttributesNode loadAttributes(ObjectReader reader, AnyObjectId id) throws IOException
nextback to summary
public CanonicalTreeParser next()

Get this iterator, or its parent, if the tree is at eof.

Returns:CanonicalTreeParser

this iterator, or its parent, if the tree is at eof.

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
noAttributesback to summary
private static AttributesNode noAttributes()
parseEntryback to summary
private void parseEntry()
resetback to summary
public void reset(byte[] treeData)

Reset this parser to walk through the given tree data.

Parameters
treeData:byte[]

the raw tree content.

resetback to summary
public void reset(ObjectReader reader, AnyObjectId id) throws IncorrectObjectTypeException, IOException

Reset this parser to walk through the given tree.

Parameters
reader:ObjectReader

reader to use during repository access.

id:AnyObjectId

identity of the tree being parsed; used only in exception messages if data corruption is found.

Exceptions
IncorrectObjectTypeException:
the object supplied as an argument 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.
MissingObjectException:
the object supplied is not available from the repository.
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
resetRootback to summary
public CanonicalTreeParser resetRoot(final ObjectReader reader, final AnyObjectId id) throws IncorrectObjectTypeException, IOException

Reset this parser to walk through the given tree.

Parameters
reader:ObjectReader

reader to use during repository access.

id:AnyObjectId

identity of the tree being parsed; used only in exception messages if data corruption is found.

Returns:CanonicalTreeParser

the root level parser.

Exceptions
IncorrectObjectTypeException:
the object supplied as an argument 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.
MissingObjectException:
the object supplied is not available from the repository.