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

public abstract Class WorkingTreeIterator

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

Walks a working directory tree as part of a org.eclipse.jgit.treewalk.TreeWalk.

Most applications will want to use the standard implementation of this iterator, org.eclipse.jgit.treewalk.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
FileTreeIterator

Nested and Inner Type Summary

Modifier and TypeClass and Description
public abstract static class
WorkingTreeIterator.Entry

A single entry within a working directory tree.

private static class
private static class
public static enum
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.

Field Summary

Modifier and TypeField and Description
pack-priv static final 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<String>
cleanFilterCommandHolder

cached clean filter command.

private byte[]
contentId

The idBuffer() for the current entry.

private int
contentIdFromPtr

Index within entries that contentId came from.

private int
contentIdOffset

The offset of the content id in idBuffer()

private static final byte[]
private WorkingTreeIterator.Entry[]
entries

List of entries obtained from the subclass.

private static final Comparator<WorkingTreeIterator.Entry>
private int
entryCnt

Total number of entries in entries that are valid.

protected static final WorkingTreeIterator.Entry[]
EOF

An empty entry array, suitable for init(Entry[]).

private Holder<CoreConfig.EolStreamType>
eolStreamTypeHolder

cached eol stream type.

private static final byte[]
private IgnoreNode
ignoreNode

If there is a .gitignore file present, the parsed rules from it.

private static final int
private static final 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 final WorkingTreeIterator.IteratorState
state

Inherited state of this iterator, describing working tree, etc.

private final InstantComparator
timestampComparator

A comparator for Instants.

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

Constructor Summary

AccessConstructor and Description
protected
WorkingTreeIterator(WorkingTreeOptions
working tree options to be used
options
)

Create a new iterator with no parent.

protected
WorkingTreeIterator(final String
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 '/'.
prefix
,
WorkingTreeOptions
working tree options to be used
options
)

Create a new iterator with no parent and a prefix.

protected
WorkingTreeIterator(WorkingTreeIterator
parent tree iterator.
p
)

Create an iterator for a subtree of an existing iterator.

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 WorkingTreeIterator.MetadataDiff

Returns:

a org.eclipse.jgit.treewalk.WorkingTreeIterator.MetadataDiff which tells whether and how the entries metadata differ
compareMetadata
(DirCacheEntry entry)

Compare the metadata (mode, length, modification-timestamp) of the current entry and a org.eclipse.jgit.dircache.DirCacheEntry

private byte[]
computeHash(InputStream in, long length)

private static long
private static String
private boolean

Returns:

true if the content doesn't match, false if it matches
contentCheck
(DirCacheEntry
the entry to be checked
entry
,
ObjectReader
acccess to repository data if necessary
reader
)

Compares the entries content with the content in the filesystem.

protected WorkingTreeIterator.Entry

Returns:

the currently selected entry.
current
()

Obtain the current entry from this iterator.

public boolean
eof()

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

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

private InputStream
public boolean
first()

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

Is this tree iterator positioned on its first entry?

public String

Returns:

the clean filter command for the current entry or null if no such command is defined
getCleanFilterCommand
()

Get the clean filter command for the current entry.

protected DirCacheIterator

Returns:

the DirCacheIterator, or null if not set or not at the current entry
getDirCacheIterator
()

Retrieves the DirCacheIterator at the current entry if setDirCacheIterator(TreeWalk, int) was called.

public AttributesNode

Returns:

the org.eclipse.jgit.attributes.AttributesNode for the current entry.
getEntryAttributesNode
()

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

public long

Returns:

size of the content, in bytes
getEntryContentLength
()

Get the filtered input length of this entry

public Instant

Returns:

last modified time of this file
getEntryLastModifiedInstant
()

Get the last modified time of this entry.

public long

Returns:

size of this file, in bytes.
getEntryLength
()

Get the raw byte length of this entry.

public CoreConfig.EolStreamType

Returns:

the eol stream type for the current entry or null if it cannot be determined. When state or state.walk is null or the org.eclipse.jgit.treewalk.TreeWalk is not based on a org.eclipse.jgit.lib.Repository then null is returned.
getEolStreamType
()

Get the eol stream type for the current entry.

private CoreConfig.EolStreamType

Returns:

the eol stream type for the current entry or 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.
getEolStreamType
(TreeWalk.OperationType
The operationtype (checkin/checkout) which should be used
opType
)

private IgnoreNode
public FileMode

Returns:

index file mode
getIndexFileMode
(DirCacheIterator
org.eclipse.jgit.dircache.DirCacheIterator positioned at the same entry as this iterator or null if no org.eclipse.jgit.dircache.DirCacheIterator is available at this iterator's current entry
indexIter
)

Get the file mode to use for the current entry when it is to be updated in the index.

public WorkingTreeOptions

Returns:

working tree options
getOptions
()

Returns the working tree options used by this iterator.

private static String
public Repository

Returns:

the Repository
getRepository
()

Retrieves the Repository this WorkingTreeIterator operates on.

private boolean

Returns:

true if the file in the index is not binary and has CR/LF line endings, false otherwise
hasCrLfInIndex
(DirCacheIterator
iterator pointing to the current entry for the file in the index
dirCache
)

Determines whether the file was committed un-normalized.

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.

private byte[]
public int
idOffset()

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

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

protected byte[]

Returns:

non-null submodule id
idSubmodule
(WorkingTreeIterator.Entry e)

Get submodule id for given entry.

protected byte[]

Returns:

non-null submodule id
idSubmodule
(File
a java.io.File object.
directory
,
WorkingTreeIterator.Entry e)

Get submodule id using the repository at the location of the entry relative to the directory.

protected void
init(WorkingTreeIterator.Entry[]
files in the subtree of the work tree this iterator operates on
list
)

Constructor helper.

protected void
initRootIterator(Repository
the repository.
repo
)

Initialize this iterator for the root level of a repository.

private static boolean
private boolean
private boolean
isDirectoryIgnored(String pathRel, String pathAbs)

public boolean

Returns:

true if the entry was ignored by an ignore rule file.
isEntryIgnored
()

Determine if the current entry path is ignored by an ignore rule.

protected boolean

Returns:

true if the entry is ignored by an ignore rule.
isEntryIgnored
(int
the length of the path in the path buffer.
pLen
)

Determine if the entry path is ignored by an ignore rule.

private boolean

Returns:

true if the entry is ignored by an ignore rule.
isEntryIgnored
(int
the length of the path in the path buffer.
pLen
,
int
the original iterator file mode
fileMode
)

Determine if the entry path is ignored by an ignore rule.

public boolean

Returns:

true if different, false otherwise
isModeDifferent
(int
an int.
rawMode
)

Is the file mode of the current entry different than the given raw mode?

public boolean

Returns:

true if content is most likely different.
isModified
(DirCacheEntry
the entry from the dircache we want to compare against
entry
,
boolean
True if the actual file content should be checked if modification time differs.
forceContentCheck
,
ObjectReader
access to repository objects if necessary. Should not be null.
reader
)

Checks whether this entry differs from a given entry from the org.eclipse.jgit.dircache.DirCache.

public boolean
isWorkTree()

Overrides org.eclipse.jgit.treewalk.AbstractTreeIterator.isWorkTree.

Whether or not this Iterator is iterating through the working tree.

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.

public InputStream

Returns:

a stream to read from the file.
openEntryStream
()

Obtain an input stream to read the file content.

private void
private InputStream
private long
private static String
protected String

Returns:

the entry's content as a normalized string
readSymlinkTarget
(WorkingTreeIterator.Entry
to read
entry
)

Reads the target of a symlink as a string.

public void
reset()

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

Position this iterator on the first entry.

private static void
public void
setDirCacheIterator(TreeWalk
the walk that will be advancing this iterator.
walk
,
int treeId)

Define the matching org.eclipse.jgit.dircache.DirCacheIterator, to optimize ObjectIds.

public void
setWalkIgnoredDirectories(boolean
false to skip ignored directories, if possible; true to always include them in the walk
includeIgnored
)

Defines whether this WorkingTreeIterator walks ignored directories.

public boolean

Returns:

true if it does, false otherwise
walksIgnoredDirectories
()

Tells whether this WorkingTreeIterator walks ignored directories.

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