Class CanonicalTreeParser
- java.lang.Object
-
- org.eclipse.jgit.treewalk.AbstractTreeIterator
-
- org.eclipse.jgit.treewalk.CanonicalTreeParser
-
- Direct Known Subclasses:
NoteParser
public class CanonicalTreeParser extends AbstractTreeIterator
Parses raw Git trees from the canonical semi-text/semi-binary format.
-
-
Field Summary
Fields Modifier and Type Field Description private static byte[]
ATTRS
private int
currPtr
First offset withinraw
of the current entry's data.private static byte[]
EMPTY
private int
nextPtr
Offset one past the current entry (first byte of next entry).private int
prevPtr
First offset withinraw
of the prior entry.private byte[]
raw
-
Fields inherited from class org.eclipse.jgit.treewalk.AbstractTreeIterator
attributesNode, DEFAULT_PATH_SIZE, matches, matchShift, mode, parent, path, pathLen, pathOffset, zeroid
-
-
Constructor Summary
Constructors Modifier Constructor Description CanonicalTreeParser()
Create a new parser.CanonicalTreeParser(byte[] prefix, ObjectReader reader, AnyObjectId treeId)
Create a new parser for a tree appearing in a subset of a repository.private
CanonicalTreeParser(CanonicalTreeParser p)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
back(int delta)
Move to prior entry, populating this iterator with the entry data.CanonicalTreeParser
createSubtreeIterator(ObjectReader reader)
Create a new iterator for the current entry's subtree.CanonicalTreeParser
createSubtreeIterator(ObjectReader reader, MutableObjectId idBuffer)
Create a new iterator for the current entry's subtree.CanonicalTreeParser
createSubtreeIterator0(ObjectReader reader, AnyObjectId id)
Back door to quickly create a subtree iterator for any subtree.boolean
eof()
Is this tree iterator at its EOF point (no more entries)?private AttributesNode
findAttributes(ObjectReader reader)
boolean
first()
Is this tree iterator positioned on its first entry?AttributesNode
getEntryAttributesNode(ObjectReader reader)
Retrieve theAttributesNode
for the current entry.CanonicalTreeParser
getParent()
Deprecated.internal use onlyboolean
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.private static AttributesNode
loadAttributes(ObjectReader reader, AnyObjectId id)
CanonicalTreeParser
next()
Get this iterator, or its parent, if the tree is at eof.void
next(int delta)
Move to next entry, populating this iterator with the entry data.private static AttributesNode
noAttributes()
private void
parseEntry()
void
reset()
Position this iterator on the first entry.void
reset(byte[] treeData)
Reset this parser to walk through the given tree data.void
reset(ObjectReader reader, AnyObjectId id)
Reset this parser to walk through the given tree.CanonicalTreeParser
resetRoot(ObjectReader reader, AnyObjectId id)
Reset this parser to walk through the given tree.-
Methods inherited from class org.eclipse.jgit.treewalk.AbstractTreeIterator
createEmptyTreeIterator, ensurePathCapacity, findFile, findFile, getEntryFileMode, getEntryObjectId, getEntryObjectId, getEntryPathBuffer, getEntryPathHashCode, getEntryPathLength, getEntryPathString, getEntryRawMode, getName, getNameLength, getNameOffset, growPath, idEqual, isWorkTree, needsStopWalk, pathCompare, pathCompare, pathCompare, skip, stopWalk, toString
-
-
-
-
Field Detail
-
EMPTY
private static final byte[] EMPTY
-
ATTRS
private static final byte[] ATTRS
-
raw
private byte[] raw
-
prevPtr
private int prevPtr
First offset withinraw
of the prior entry.
-
currPtr
private int currPtr
First offset withinraw
of the current entry's data.
-
nextPtr
private int nextPtr
Offset one past the current entry (first byte of next entry).
-
-
Constructor Detail
-
CanonicalTreeParser
public CanonicalTreeParser()
Create a new parser.
-
CanonicalTreeParser
public CanonicalTreeParser(byte[] prefix, ObjectReader reader, AnyObjectId treeId) throws IncorrectObjectTypeException, java.io.IOException
Create a new parser for a tree appearing in a subset of a repository.- Parameters:
prefix
- 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
- reader to load the tree data from.treeId
- identity of the tree being parsed; used only in exception messages if data corruption is found.- Throws:
MissingObjectException
- the object supplied is not available from the repository.IncorrectObjectTypeException
- the object supplied as an argument 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.
-
CanonicalTreeParser
private CanonicalTreeParser(CanonicalTreeParser p)
-
-
Method Detail
-
getParent
@Deprecated public CanonicalTreeParser getParent()
Deprecated.internal use onlyGet the parent of this tree parser.- Returns:
- the parent of this tree parser.
-
reset
public void reset(byte[] treeData)
Reset this parser to walk through the given tree data.- Parameters:
treeData
- the raw tree content.
-
resetRoot
public CanonicalTreeParser resetRoot(ObjectReader reader, AnyObjectId id) throws IncorrectObjectTypeException, java.io.IOException
Reset this parser to walk through the given tree.- Parameters:
reader
- reader to use during repository access.id
- identity of the tree being parsed; used only in exception messages if data corruption is found.- Returns:
- the root level parser.
- Throws:
MissingObjectException
- the object supplied is not available from the repository.IncorrectObjectTypeException
- the object supplied as an argument 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.
-
next
public CanonicalTreeParser next()
Get this iterator, or its parent, if the tree is at eof.- Returns:
- this iterator, or its parent, if the tree is at eof.
-
reset
public void reset(ObjectReader reader, AnyObjectId id) throws IncorrectObjectTypeException, java.io.IOException
Reset this parser to walk through the given tree.- Parameters:
reader
- reader to use during repository access.id
- identity of the tree being parsed; used only in exception messages if data corruption is found.- Throws:
MissingObjectException
- the object supplied is not available from the repository.IncorrectObjectTypeException
- the object supplied as an argument 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.
-
createSubtreeIterator
public CanonicalTreeParser createSubtreeIterator(ObjectReader reader, MutableObjectId idBuffer) throws IncorrectObjectTypeException, java.io.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
.- Overrides:
createSubtreeIterator
in classAbstractTreeIterator
- Parameters:
reader
- reader to load the tree data from.idBuffer
- temporary ObjectId buffer for use by this method.- 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.
-
createSubtreeIterator0
public final CanonicalTreeParser createSubtreeIterator0(ObjectReader reader, AnyObjectId id) throws java.io.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
- reader to load the tree data from.id
- ObjectId of the tree to open.- Returns:
- a new parser that walks over the current subtree.
- Throws:
java.io.IOException
- a loose object or pack file could not be read.
-
createSubtreeIterator
public CanonicalTreeParser createSubtreeIterator(ObjectReader reader) throws IncorrectObjectTypeException, java.io.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.java.io.IOException
- a loose object or pack file could not be read.
-
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:
AbstractTreeIterator.getEntryObjectId()
-
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()
-
getEntryAttributesNode
public AttributesNode getEntryAttributesNode(ObjectReader reader) throws java.io.IOException
Retrieve theAttributesNode
for the current entry.- Parameters:
reader
-ObjectReader
used to parse the .gitattributes entry.- Returns:
AttributesNode
for the current entry.- Throws:
java.io.IOException
- Since:
- 4.2
-
findAttributes
private AttributesNode findAttributes(ObjectReader reader) throws java.io.IOException
- Throws:
java.io.IOException
-
loadAttributes
private static AttributesNode loadAttributes(ObjectReader reader, AnyObjectId id) throws java.io.IOException
- Throws:
java.io.IOException
-
noAttributes
private static AttributesNode noAttributes()
-
-