- Direct Known Subclasses:
FileTreeIterator
TreeWalk.
Most applications will want to use the standard implementation of this
iterator, FileTreeIterator, as that does
all IO through the standard java.io package. Plugins for a Java
based IDE may however wish to create their own implementations of this class
to allow traversal of the IDE's project space, as well as benefit from any
caching the IDE may have.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA single entry within a working directory tree.static enumThe result of a metadata-comparison between the current entry and aDirCacheEntry -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final WorkingTreeIterator.Entry[]An empty entry array, suitable forinit(Entry[]).protected RepositoryRepository that is the root level being iterated overFields inherited from class org.eclipse.jgit.treewalk.AbstractTreeIterator
attributesNode, DEFAULT_PATH_SIZE, mode, parent, path, pathLen, pathOffset, zeroid -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedWorkingTreeIterator(String prefix, WorkingTreeOptions options) Create a new iterator with no parent and a prefix.protectedCreate an iterator for a subtree of an existing iterator.protectedWorkingTreeIterator(WorkingTreeOptions options) Create a new iterator with no parent. -
Method Summary
Modifier and TypeMethodDescriptionvoidback(int delta) Move to prior entry, populating this iterator with the entry data.compareMetadata(DirCacheEntry entry) Compare the metadata (mode, length, modification-timestamp) of the current entry and aDirCacheEntryprotected WorkingTreeIterator.Entrycurrent()Obtain the current entry from this iterator.booleaneof()Is this tree iterator at its EOF point (no more entries)?booleanfirst()Is this tree iterator positioned on its first entry?Get the clean filter command for the current entry.protected DirCacheIteratorRetrieves theDirCacheIteratorat the current entry ifsetDirCacheIterator(TreeWalk, int)was called.Retrieves theAttributesNodefor the current entry.longGet the filtered input length of this entryGet the last modified time of this entry.longGet the raw byte length of this entry.Get the eol stream type for the current entry.getIndexFileMode(DirCacheIterator indexIter) Get the file mode to use for the current entry when it is to be updated in the index.Returns the working tree options used by this iterator.Retrieves theRepositorythisWorkingTreeIteratoroperates on.booleanhasId()Whether the entry has a valid ObjectId.byte[]idBuffer()Get the byte array buffer object IDs must be copied out of.intidOffset()Get the position withinAbstractTreeIterator.idBuffer()of this entry's ObjectId.protected byte[]idSubmodule(File directory, WorkingTreeIterator.Entry e) Get submodule id using the repository at the location of the entry relative to the directory.protected byte[]Get submodule id for given entry.protected voidinit(WorkingTreeIterator.Entry[] list) Constructor helper.protected voidinitRootIterator(Repository repo) Initialize this iterator for the root level of a repository.booleanDetermine if the current entry path is ignored by an ignore rule.protected booleanisEntryIgnored(int pLen) Determine if the entry path is ignored by an ignore rule.booleanisModeDifferent(int rawMode) Is the file mode of the current entry different than the given raw mode?booleanisModified(DirCacheEntry entry, boolean forceContentCheck, ObjectReader reader) Checks whether this entry differs from a given entry from theDirCache.booleanWhether or not this Iterator is iterating through the working tree.voidnext(int delta) Move to next entry, populating this iterator with the entry data.Obtain an input stream to read the file content.protected StringReads the target of a symlink as a string.voidreset()Position this iterator on the first entry.voidsetDirCacheIterator(TreeWalk walk, int treeId) Define the matchingDirCacheIterator, to optimize ObjectIds.voidsetWalkIgnoredDirectories(boolean includeIgnored) Defines whether thisWorkingTreeIteratorwalks ignored directories.booleanTells whether thisWorkingTreeIteratorwalks ignored directories.Methods inherited from class org.eclipse.jgit.treewalk.AbstractTreeIterator
createEmptyTreeIterator, createSubtreeIterator, createSubtreeIterator, ensurePathCapacity, findFile, findFile, getEntryFileMode, getEntryObjectId, getEntryObjectId, getEntryPathBuffer, getEntryPathHashCode, getEntryPathLength, getEntryPathString, getEntryRawMode, getName, getNameLength, getNameOffset, growPath, idEqual, needsStopWalk, pathCompare, pathCompare, skip, stopWalk, toString
-
Field Details
-
EOF
An empty entry array, suitable forinit(Entry[]). -
repository
Repository that is the root level being iterated over
-
-
Constructor Details
-
WorkingTreeIterator
Create a new iterator with no parent.- Parameters:
options- working tree options to be used
-
WorkingTreeIterator
Create a new iterator with no parent and a prefix.The prefix path supplied is inserted in front of all paths generated by this iterator. It is intended to be used when an iterator is being created for a subsection of an overall repository and needs to be combined with other iterators that are created to run over the entire repository namespace.
- Parameters:
prefix- position of this iterator in the repository tree. The value may be null or the empty string to indicate the prefix is the root of the repository. A trailing slash ('/') is automatically appended if the prefix does not end in '/'.options- working tree options to be used
-
WorkingTreeIterator
Create an iterator for a subtree of an existing iterator.- Parameters:
p- parent tree iterator.
-
-
Method Details
-
initRootIterator
Initialize this iterator for the root level of a repository.This method should only be invoked after calling
init(Entry[]), and only for the root iterator.- Parameters:
repo- the repository.
-
setDirCacheIterator
Define the matchingDirCacheIterator, to optimize ObjectIds. Once the DirCacheIterator has been set this iterator must only be advanced by the TreeWalk that is supplied, as it assumes that itself and the corresponding DirCacheIterator are positioned on the same file path wheneveridBuffer()is invoked.- Parameters:
walk- the walk that will be advancing this iterator.treeId- index of the matchingDirCacheIterator.
-
getDirCacheIterator
Retrieves theDirCacheIteratorat the current entry ifsetDirCacheIterator(TreeWalk, int)was called.- Returns:
- the DirCacheIterator, or
nullif not set or not at the current entry - Since:
- 5.0
-
setWalkIgnoredDirectories
public void setWalkIgnoredDirectories(boolean includeIgnored) Defines whether thisWorkingTreeIteratorwalks ignored directories.- Parameters:
includeIgnored-falseto skip ignored directories, if possible;trueto always include them in the walk- Since:
- 5.0
-
walksIgnoredDirectories
public boolean walksIgnoredDirectories()Tells whether thisWorkingTreeIteratorwalks ignored directories.- Returns:
trueif it does,falseotherwise- Since:
- 5.0
-
hasId
public boolean hasId()Description copied from class:AbstractTreeIteratorWhether the entry has a valid ObjectId.- Specified by:
hasIdin classAbstractTreeIterator- Returns:
trueif the entry has a valid ObjectId.
-
idBuffer
public byte[] idBuffer()Description copied from class:AbstractTreeIteratorGet 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:
idBufferin classAbstractTreeIterator- Returns:
- byte array the implementation stores object IDs within.
- See Also:
-
isWorkTree
public boolean isWorkTree()Description copied from class:AbstractTreeIteratorWhether or not this Iterator is iterating through the working tree.- Overrides:
isWorkTreein classAbstractTreeIterator- Returns:
- whether or not this Iterator is iterating through the working tree
-
idSubmodule
Get submodule id for given entry.- Parameters:
e- aWorkingTreeIterator.Entryobject.- Returns:
- non-null submodule id
-
idSubmodule
Get submodule id using the repository at the location of the entry relative to the directory.- Parameters:
directory- aFileobject.e- aWorkingTreeIterator.Entryobject.- Returns:
- non-null submodule id
-
getOptions
Returns the working tree options used by this iterator.- Returns:
- working tree options
-
getRepository
Retrieves theRepositorythisWorkingTreeIteratoroperates on.- Returns:
- the
Repository - Since:
- 5.9
-
idOffset
public int idOffset()Description copied from class:AbstractTreeIteratorGet the position withinAbstractTreeIterator.idBuffer()of this entry's ObjectId.- Specified by:
idOffsetin classAbstractTreeIterator- Returns:
- offset into the array returned by
AbstractTreeIterator.idBuffer()where the ObjectId must be copied out of.
-
reset
public void reset()Description copied from class:AbstractTreeIteratorPosition 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:
resetin classAbstractTreeIterator
-
first
public boolean first()Description copied from class:AbstractTreeIteratorIs 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:
firstin classAbstractTreeIterator- Returns:
- true if the iterator is positioned on the first entry.
-
eof
public boolean eof()Description copied from class:AbstractTreeIteratorIs this tree iterator at its EOF point (no more entries)?An iterator is at EOF if there is no current entry.
- Specified by:
eofin classAbstractTreeIterator- Returns:
- true if we have walked all entries and have none left.
-
next
Description copied from class:AbstractTreeIteratorMove 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.modeAbstractTreeIterator.path(fromAbstractTreeIterator.pathOffsettoAbstractTreeIterator.pathLen)AbstractTreeIterator.pathLen
AbstractTreeIterator.idBuffer()andAbstractTreeIterator.idOffset()when demanded.- Specified by:
nextin classAbstractTreeIterator- Parameters:
delta- number of entries to move the iterator by. Must be a positive, non-zero integer.- Throws:
CorruptObjectException- the tree is invalid.
-
back
Description copied from class:AbstractTreeIteratorMove 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.modeAbstractTreeIterator.path(fromAbstractTreeIterator.pathOffsettoAbstractTreeIterator.pathLen)AbstractTreeIterator.pathLen
AbstractTreeIterator.idBuffer()andAbstractTreeIterator.idOffset()when demanded.- Specified by:
backin classAbstractTreeIterator- Parameters:
delta- number of entries to move the iterator by. Must be a positive, non-zero integer.- Throws:
CorruptObjectException- the tree is invalid.
-
getEntryLength
public long getEntryLength()Get the raw byte length of this entry.- Returns:
- size of this file, in bytes.
-
getEntryContentLength
Get the filtered input length of this entry- Returns:
- size of the content, in bytes
- Throws:
IOException- if an IO error occurred
-
getEntryLastModifiedInstant
Get the last modified time of this entry.- Returns:
- last modified time of this file
- Since:
- 5.1.9
-
openEntryStream
Obtain an input stream to read the file content.Efficient implementations are not required. The caller will usually obtain the stream only once per entry, if at all.
The input stream should not use buffering if the implementation can avoid it. The caller will buffer as necessary to perform efficient block IO operations.
The caller will close the stream once complete.
- Returns:
- a stream to read from the file.
- Throws:
IOException- the file could not be opened for reading.
-
isEntryIgnored
Determine if the current entry path is ignored by an ignore rule.- Returns:
- true if the entry was ignored by an ignore rule file.
- Throws:
IOException- a relevant ignore rule file exists but cannot be read.
-
isEntryIgnored
Determine if the entry path is ignored by an ignore rule.- Parameters:
pLen- the length of the path in the path buffer.- Returns:
- true if the entry is ignored by an ignore rule.
- Throws:
IOException- a relevant ignore rule file exists but cannot be read.
-
getEntryAttributesNode
Retrieves theAttributesNodefor the current entry.- Returns:
- the
AttributesNodefor the current entry. - Throws:
IOException- if an IO error occurred
-
init
Constructor helper.- Parameters:
list- files in the subtree of the work tree this iterator operates on
-
current
Obtain the current entry from this iterator.- Returns:
- the currently selected entry.
-
isModeDifferent
public boolean isModeDifferent(int rawMode) Is the file mode of the current entry different than the given raw mode?- Parameters:
rawMode- an int.- Returns:
- true if different, false otherwise
-
compareMetadata
Compare the metadata (mode, length, modification-timestamp) of the current entry and aDirCacheEntry- Parameters:
entry- theDirCacheEntryto compare with- Returns:
- a
WorkingTreeIterator.MetadataDiffwhich tells whether and how the entries metadata differ
-
isModified
public boolean isModified(DirCacheEntry entry, boolean forceContentCheck, ObjectReader reader) throws IOException Checks whether this entry differs from a given entry from theDirCache. File status information is used and if status is same we consider the file identical to the state in the working directory. Native git uses more stat fields than we have accessible in Java.- Parameters:
entry- the entry from the dircache we want to compare againstforceContentCheck- True if the actual file content should be checked if modification time differs.reader- access to repository objects if necessary. Should not be null.- Returns:
- true if content is most likely different.
- Throws:
IOException- if an IO error occurred- Since:
- 3.3
-
getIndexFileMode
Get the file mode to use for the current entry when it is to be updated in the index.- Parameters:
indexIter-DirCacheIteratorpositioned at the same entry as this iterator or null if noDirCacheIteratoris available at this iterator's current entry- Returns:
- index file mode
-
readSymlinkTarget
Reads the target of a symlink as a string. This default implementation fully reads the entry's input stream and converts it to a normalized string. Subclasses may override to provide more specialized implementations.- Parameters:
entry- to read- Returns:
- the entry's content as a normalized string
- Throws:
IOException- if the entry cannot be read or does not denote a symlink- Since:
- 4.6
-
getCleanFilterCommand
Get the clean filter command for the current entry.- Returns:
- the clean filter command for the current entry or
nullif no such command is defined - Throws:
IOException- if an IO error occurred- Since:
- 4.2
-
getEolStreamType
Get the eol stream type for the current entry.- Returns:
- the eol stream type for the current entry or
nullif it cannot be determined. When state or state.walk is null or theTreeWalkis not based on aRepositorythen null is returned. - Throws:
IOException- if an IO error occurred- Since:
- 4.3
-