public abstract class WorkingTreeIterator extends AbstractTreeIterator
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.
FileTreeIterator
Modifier and Type | Class and Description |
---|---|
static class |
WorkingTreeIterator.Entry
A single entry within a working directory tree.
|
private static class |
WorkingTreeIterator.IteratorState |
static class |
WorkingTreeIterator.MetadataDiff
The result of a metadata-comparison between the current entry and a
DirCacheEntry |
private static class |
WorkingTreeIterator.PerDirectoryAttributesNode
Magic type indicating we know rules exist, but they aren't loaded.
|
private static class |
WorkingTreeIterator.PerDirectoryIgnoreNode
Magic type indicating we know rules exist, but they aren't loaded.
|
private static class |
WorkingTreeIterator.RootIgnoreNode
Magic type indicating there may be rules for the top level.
|
Modifier and Type | Field and Description |
---|---|
(package private) static int |
BUFFER_SIZE
Size we perform file IO in if we have to read and hash a file.
|
private long |
canonLen
Cached canonical length, initialized from
idBuffer() |
private Holder<java.lang.String> |
cleanFilterCommandHolder
cached clean filter command.
|
private byte[] |
contentId
The
idBuffer() for the current entry. |
private int |
contentIdFromPtr
|
private int |
contentIdOffset
The offset of the content id in
idBuffer() |
private static byte[] |
digits |
private WorkingTreeIterator.Entry[] |
entries
List of entries obtained from the subclass.
|
private static java.util.Comparator<WorkingTreeIterator.Entry> |
ENTRY_CMP |
private int |
entryCnt
Total number of entries in
entries that are valid. |
protected static WorkingTreeIterator.Entry[] |
EOF
An empty entry array, suitable for
init(Entry[]) . |
private Holder<CoreConfig.EolStreamType> |
eolStreamTypeHolder
cached eol stream type.
|
private static byte[] |
hblob |
private IgnoreNode |
ignoreNode
If there is a .gitignore file present, the parsed rules from it.
|
private static int |
MAX_EXCEPTION_TEXT_SIZE |
private static long |
MAXIMUM_FILE_SIZE_TO_READ_FULLY
Maximum size of files which may be read fully into memory for performance
reasons.
|
private int |
ptr
Current position within
entries . |
protected Repository |
repository
Repository that is the root level being iterated over
|
private WorkingTreeIterator.IteratorState |
state
Inherited state of this iterator, describing working tree, etc.
|
private InstantComparator |
timestampComparator
A comparator for
Instant s. |
attributesNode, DEFAULT_PATH_SIZE, matches, matchShift, mode, parent, path, pathLen, pathOffset, zeroid
Modifier | Constructor and Description |
---|---|
protected |
WorkingTreeIterator(java.lang.String prefix,
WorkingTreeOptions options)
Create a new iterator with no parent and a prefix.
|
protected |
WorkingTreeIterator(WorkingTreeIterator p)
Create an iterator for a subtree of an existing iterator.
|
protected |
WorkingTreeIterator(WorkingTreeOptions options)
Create a new iterator with no parent.
|
Modifier and Type | Method and Description |
---|---|
void |
back(int delta)
Move to prior entry, populating this iterator with the entry data.
|
WorkingTreeIterator.MetadataDiff |
compareMetadata(DirCacheEntry entry)
Compare the metadata (mode, length, modification-timestamp) of the
current entry and a
DirCacheEntry |
private byte[] |
computeHash(java.io.InputStream in,
long length) |
private static long |
computeLength(java.io.InputStream in) |
private static java.lang.String |
concatPath(java.lang.String p1,
java.lang.String p2) |
private boolean |
contentCheck(DirCacheEntry entry,
ObjectReader reader)
Compares the entries content with the content in the filesystem.
|
protected WorkingTreeIterator.Entry |
current()
Obtain the current entry from this iterator.
|
boolean |
eof()
Is this tree iterator at its EOF point (no more entries)?
|
private java.nio.ByteBuffer |
filterClean(byte[] src,
int n,
TreeWalk.OperationType opType) |
private java.io.InputStream |
filterClean(java.io.InputStream in) |
private java.io.InputStream |
filterClean(java.io.InputStream in,
TreeWalk.OperationType opType) |
boolean |
first()
Is this tree iterator positioned on its first entry?
|
java.lang.String |
getCleanFilterCommand()
Get the clean filter command for the current entry.
|
protected DirCacheIterator |
getDirCacheIterator()
Retrieves the
DirCacheIterator at the current entry if
setDirCacheIterator(TreeWalk, int) was called. |
AttributesNode |
getEntryAttributesNode()
Retrieves the
AttributesNode for the
current entry. |
long |
getEntryContentLength()
Get the filtered input length of this entry
|
long |
getEntryLastModified()
Deprecated.
use
getEntryLastModifiedInstant() instead |
java.time.Instant |
getEntryLastModifiedInstant()
Get the last modified time of this entry.
|
long |
getEntryLength()
Get the raw byte length of this entry.
|
CoreConfig.EolStreamType |
getEolStreamType()
Get the eol stream type for the current entry.
|
private CoreConfig.EolStreamType |
getEolStreamType(TreeWalk.OperationType opType) |
private IgnoreNode |
getIgnoreNode() |
FileMode |
getIndexFileMode(DirCacheIterator indexIter)
Get the file mode to use for the current entry when it is to be updated
in the index.
|
WorkingTreeOptions |
getOptions()
Returns the working tree options used by this iterator.
|
private static java.lang.String |
getParentPath(java.lang.String path) |
private java.io.InputStream |
handleAutoCRLF(java.io.InputStream in,
TreeWalk.OperationType opType) |
private boolean |
hasCrLfInIndex(DirCacheIterator dirCache)
Determines whether the file was committed un-normalized.
|
boolean |
hasId()
Whether the entry has a valid ObjectId.
|
byte[] |
idBuffer()
Get the byte array buffer object IDs must be copied out of.
|
private byte[] |
idBufferBlob(WorkingTreeIterator.Entry e) |
int |
idOffset()
Get the position within
AbstractTreeIterator.idBuffer() of this entry's ObjectId. |
protected byte[] |
idSubmodule(java.io.File directory,
WorkingTreeIterator.Entry e)
Get submodule id using the repository at the location of the entry
relative to the directory.
|
protected byte[] |
idSubmodule(WorkingTreeIterator.Entry e)
Get submodule id for given entry.
|
protected void |
init(WorkingTreeIterator.Entry[] list)
Constructor helper.
|
protected void |
initRootIterator(Repository repo)
Initialize this iterator for the root level of a repository.
|
private static boolean |
isBinary(WorkingTreeIterator.Entry entry) |
private boolean |
isDirectoryIgnored(java.lang.String pathRel) |
private boolean |
isDirectoryIgnored(java.lang.String pathRel,
java.lang.String pathAbs) |
boolean |
isEntryIgnored()
Determine if the current entry path is ignored by an ignore rule.
|
protected boolean |
isEntryIgnored(int pLen)
Determine if the entry path is ignored by an ignore rule.
|
private boolean |
isEntryIgnored(int pLen,
int fileMode)
Determine if the entry path is ignored by an ignore rule.
|
boolean |
isModeDifferent(int rawMode)
Is the file mode of the current entry different than the given raw mode?
|
boolean |
isModified(DirCacheEntry entry,
boolean forceContentCheck,
ObjectReader reader)
Checks whether this entry differs from a given entry from the
DirCache . |
boolean |
isWorkTree()
Whether or not this Iterator is iterating through the working tree.
|
void |
next(int delta)
Move to next entry, populating this iterator with the entry data.
|
java.io.InputStream |
openEntryStream()
Obtain an input stream to read the file content.
|
private void |
parseEntry() |
private java.io.InputStream |
possiblyFilteredInputStream(WorkingTreeIterator.Entry e,
java.io.InputStream is,
long len) |
private java.io.InputStream |
possiblyFilteredInputStream(WorkingTreeIterator.Entry e,
java.io.InputStream is,
long len,
TreeWalk.OperationType opType) |
private static java.lang.String |
readContentAsNormalizedString(DirCacheEntry entry,
ObjectReader reader) |
protected java.lang.String |
readSymlinkTarget(WorkingTreeIterator.Entry entry)
Reads the target of a symlink as a string.
|
void |
reset()
Position this iterator on the first entry.
|
private static void |
safeClose(java.io.InputStream in) |
void |
setDirCacheIterator(TreeWalk walk,
int treeId)
Define the matching
DirCacheIterator ,
to optimize ObjectIds. |
void |
setWalkIgnoredDirectories(boolean includeIgnored)
Defines whether this
WorkingTreeIterator walks ignored
directories. |
boolean |
walksIgnoredDirectories()
Tells whether this
WorkingTreeIterator walks ignored directories. |
createEmptyTreeIterator, createSubtreeIterator, createSubtreeIterator, ensurePathCapacity, findFile, findFile, getEntryFileMode, getEntryObjectId, getEntryObjectId, getEntryPathBuffer, getEntryPathHashCode, getEntryPathLength, getEntryPathString, getEntryRawMode, getName, getNameLength, getNameOffset, growPath, idEqual, needsStopWalk, pathCompare, pathCompare, pathCompare, skip, stopWalk, toString
private static final int MAX_EXCEPTION_TEXT_SIZE
protected static final WorkingTreeIterator.Entry[] EOF
init(Entry[])
.static final int BUFFER_SIZE
private static final long MAXIMUM_FILE_SIZE_TO_READ_FULLY
private final WorkingTreeIterator.IteratorState state
private byte[] contentId
idBuffer()
for the current entry.private int contentIdFromPtr
private WorkingTreeIterator.Entry[] entries
private int entryCnt
entries
that are valid.private int ptr
entries
.private IgnoreNode ignoreNode
private Holder<java.lang.String> cleanFilterCommandHolder
private Holder<CoreConfig.EolStreamType> eolStreamTypeHolder
protected Repository repository
private long canonLen
idBuffer()
private int contentIdOffset
idBuffer()
private final InstantComparator timestampComparator
Instant
s.private static final byte[] digits
private static final byte[] hblob
private static final java.util.Comparator<WorkingTreeIterator.Entry> ENTRY_CMP
protected WorkingTreeIterator(WorkingTreeOptions options)
options
- working tree options to be usedprotected WorkingTreeIterator(java.lang.String prefix, WorkingTreeOptions options)
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.
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 usedprotected WorkingTreeIterator(WorkingTreeIterator p)
p
- parent tree iterator.protected void initRootIterator(Repository repo)
This method should only be invoked after calling init(Entry[])
,
and only for the root iterator.
repo
- the repository.public void setDirCacheIterator(TreeWalk walk, int treeId)
DirCacheIterator
,
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
whenever idBuffer()
is invoked.walk
- the walk that will be advancing this iterator.treeId
- index of the matching
DirCacheIterator
.protected DirCacheIterator getDirCacheIterator()
DirCacheIterator
at the current entry if
setDirCacheIterator(TreeWalk, int)
was called.null
if not set or not at the
current entrypublic void setWalkIgnoredDirectories(boolean includeIgnored)
WorkingTreeIterator
walks ignored
directories.includeIgnored
- false
to skip ignored directories, if possible;
true
to always include them in the walkpublic boolean walksIgnoredDirectories()
WorkingTreeIterator
walks ignored directories.true
if it does, false
otherwisepublic boolean hasId()
hasId
in class AbstractTreeIterator
true
if the entry has a valid ObjectId.public byte[] idBuffer()
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.
idBuffer
in class AbstractTreeIterator
AbstractTreeIterator.getEntryObjectId()
public boolean isWorkTree()
isWorkTree
in class AbstractTreeIterator
protected byte[] idSubmodule(WorkingTreeIterator.Entry e)
e
- a WorkingTreeIterator.Entry
object.protected byte[] idSubmodule(java.io.File directory, WorkingTreeIterator.Entry e)
directory
- a File
object.e
- a WorkingTreeIterator.Entry
object.private byte[] idBufferBlob(WorkingTreeIterator.Entry e)
private java.io.InputStream possiblyFilteredInputStream(WorkingTreeIterator.Entry e, java.io.InputStream is, long len) throws java.io.IOException
java.io.IOException
private java.io.InputStream possiblyFilteredInputStream(WorkingTreeIterator.Entry e, java.io.InputStream is, long len, TreeWalk.OperationType opType) throws java.io.IOException
java.io.IOException
private static void safeClose(java.io.InputStream in)
private static boolean isBinary(WorkingTreeIterator.Entry entry) throws java.io.IOException
java.io.IOException
private java.nio.ByteBuffer filterClean(byte[] src, int n, TreeWalk.OperationType opType) throws java.io.IOException
java.io.IOException
private java.io.InputStream filterClean(java.io.InputStream in) throws java.io.IOException
java.io.IOException
private java.io.InputStream filterClean(java.io.InputStream in, TreeWalk.OperationType opType) throws java.io.IOException
java.io.IOException
private java.io.InputStream handleAutoCRLF(java.io.InputStream in, TreeWalk.OperationType opType) throws java.io.IOException
java.io.IOException
public WorkingTreeOptions getOptions()
public int idOffset()
AbstractTreeIterator.idBuffer()
of this entry's ObjectId.idOffset
in class AbstractTreeIterator
AbstractTreeIterator.idBuffer()
where the
ObjectId must be copied out of.public void reset()
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.reset
in class AbstractTreeIterator
public boolean first()
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()
.
first
in class AbstractTreeIterator
public boolean eof()
An iterator is at EOF if there is no current entry.
eof
in class AbstractTreeIterator
public void next(int delta) throws CorruptObjectException
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
(from AbstractTreeIterator.pathOffset
to AbstractTreeIterator.pathLen
)AbstractTreeIterator.pathLen
AbstractTreeIterator.idBuffer()
and AbstractTreeIterator.idOffset()
when demanded.next
in class AbstractTreeIterator
delta
- number of entries to move the iterator by. Must be a positive,
non-zero integer.CorruptObjectException
- the tree is invalid.public void back(int delta) throws CorruptObjectException
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
(from AbstractTreeIterator.pathOffset
to AbstractTreeIterator.pathLen
)AbstractTreeIterator.pathLen
AbstractTreeIterator.idBuffer()
and AbstractTreeIterator.idOffset()
when demanded.back
in class AbstractTreeIterator
delta
- number of entries to move the iterator by. Must be a positive,
non-zero integer.CorruptObjectException
- the tree is invalid.private void parseEntry()
public long getEntryLength()
public long getEntryContentLength() throws java.io.IOException
java.io.IOException
@Deprecated public long getEntryLastModified()
getEntryLastModifiedInstant()
insteadpublic java.time.Instant getEntryLastModifiedInstant()
public java.io.InputStream openEntryStream() throws java.io.IOException
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.
java.io.IOException
- the file could not be opened for reading.public boolean isEntryIgnored() throws java.io.IOException
java.io.IOException
- a relevant ignore rule file exists but cannot be read.protected boolean isEntryIgnored(int pLen) throws java.io.IOException
pLen
- the length of the path in the path buffer.java.io.IOException
- a relevant ignore rule file exists but cannot be read.private boolean isEntryIgnored(int pLen, int fileMode) throws java.io.IOException
pLen
- the length of the path in the path buffer.fileMode
- the original iterator file modejava.io.IOException
- a relevant ignore rule file exists but cannot be read.private IgnoreNode getIgnoreNode() throws java.io.IOException
java.io.IOException
public AttributesNode getEntryAttributesNode() throws java.io.IOException
AttributesNode
for the
current entry.AttributesNode
for the
current entry.java.io.IOException
protected void init(WorkingTreeIterator.Entry[] list)
list
- files in the subtree of the work tree this iterator operates
onprotected WorkingTreeIterator.Entry current()
public boolean isModeDifferent(int rawMode)
rawMode
- an int.public WorkingTreeIterator.MetadataDiff compareMetadata(DirCacheEntry entry)
DirCacheEntry
entry
- the DirCacheEntry
to compare
withWorkingTreeIterator.MetadataDiff
which tells whether and how the entries metadata differpublic boolean isModified(DirCacheEntry entry, boolean forceContentCheck, ObjectReader reader) throws java.io.IOException
DirCache
.
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.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.java.io.IOException
public FileMode getIndexFileMode(DirCacheIterator indexIter)
indexIter
- DirCacheIterator
positioned
at the same entry as this iterator or null if no
DirCacheIterator
is
available at this iterator's current entryprivate boolean contentCheck(DirCacheEntry entry, ObjectReader reader) throws java.io.IOException
entry
- the entry to be checkedreader
- acccess to repository data if necessarytrue
if the content doesn't match,
false
if it matchesjava.io.IOException
private static java.lang.String readContentAsNormalizedString(DirCacheEntry entry, ObjectReader reader) throws MissingObjectException, java.io.IOException
MissingObjectException
java.io.IOException
protected java.lang.String readSymlinkTarget(WorkingTreeIterator.Entry entry) throws java.io.IOException
entry
- to readjava.io.IOException
- if the entry cannot be read or does not denote a symlinkprivate static long computeLength(java.io.InputStream in) throws java.io.IOException
java.io.IOException
private byte[] computeHash(java.io.InputStream in, long length) throws java.io.IOException
java.io.IOException
public java.lang.String getCleanFilterCommand() throws java.io.IOException
null
if no such command is definedjava.io.IOException
public CoreConfig.EolStreamType getEolStreamType() throws java.io.IOException
null
if
it cannot be determined. When state or state.walk is null or the
TreeWalk
is not based on a
Repository
then null is returned.java.io.IOException
private CoreConfig.EolStreamType getEolStreamType(TreeWalk.OperationType opType) throws java.io.IOException
opType
- The operationtype (checkin/checkout) which should be usednull
if
it cannot be determined. When state or state.walk is null or the
TreeWalk
is not based on a Repository
then null
is returned.java.io.IOException
private boolean hasCrLfInIndex(DirCacheIterator dirCache)
dirCache
- iterator pointing to the current entry for the file in the
indextrue
if the file in the index is not binary and has CR/LF
line endings, false
otherwiseprivate boolean isDirectoryIgnored(java.lang.String pathRel) throws java.io.IOException
java.io.IOException
private boolean isDirectoryIgnored(java.lang.String pathRel, java.lang.String pathAbs) throws java.io.IOException
java.io.IOException
private static java.lang.String getParentPath(java.lang.String path)
private static java.lang.String concatPath(java.lang.String p1, java.lang.String p2)