Package org.eclipse.jgit.treewalk
Class FileTreeIterator
java.lang.Object
org.eclipse.jgit.treewalk.AbstractTreeIterator
org.eclipse.jgit.treewalk.WorkingTreeIterator
org.eclipse.jgit.treewalk.FileTreeIterator
Working directory iterator for standard Java IO.
This iterator uses the standard java.io
package to read the
specified working directory as part of a
TreeWalk
.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
A default implementation of a FileModeStrategy; defaults to treating nested .git directories as gitlinks, etc.static class
Wrapper for a standard Java IO filestatic interface
An interface representing the methods used to determine the FileMode for a FileEntry.static class
A FileModeStrategy that implements native git's DIR_NO_GITLINKS behavior.Nested classes/interfaces inherited from class org.eclipse.jgit.treewalk.WorkingTreeIterator
WorkingTreeIterator.Entry, WorkingTreeIterator.MetadataDiff
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final File
the starting directory of this Iterator.protected final FileTreeIterator.FileModeStrategy
the strategy used to compute the FileMode for a FileEntry.protected final FS
the file system abstraction which will be necessary to perform certain file system operations.Fields inherited from class org.eclipse.jgit.treewalk.WorkingTreeIterator
BUFFER_SIZE, EOF, repository
Fields inherited from class org.eclipse.jgit.treewalk.AbstractTreeIterator
attributesNode, DEFAULT_PATH_SIZE, matches, matchShift, mode, parent, path, pathLen, pathOffset, zeroid
-
Constructor Summary
ConstructorsModifierConstructorDescriptionFileTreeIterator
(File root, FS fs, WorkingTreeOptions options) Create a new iterator to traverse the given directory and its children.FileTreeIterator
(File root, FS fs, WorkingTreeOptions options, FileTreeIterator.FileModeStrategy fileModeStrategy) Create a new iterator to traverse the given directory and its children.FileTreeIterator
(Repository repo) Create a new iterator to traverse the work tree and its children.FileTreeIterator
(Repository repo, FileTreeIterator.FileModeStrategy fileModeStrategy) Create a new iterator to traverse the work tree and its children.protected
FileTreeIterator
(FileTreeIterator p, File root, FS fs) Create a new iterator to traverse a subdirectory.protected
FileTreeIterator
(WorkingTreeIterator p, File root, FS fs, FileTreeIterator.FileModeStrategy fileModeStrategy) Create a new iterator to traverse a subdirectory, given the specified FileModeStrategy. -
Method Summary
Modifier and TypeMethodDescriptioncreateSubtreeIterator
(ObjectReader reader) Create a new iterator for the current entry's subtree.protected AbstractTreeIterator
Create a new iterator for the current entry's subtree.private WorkingTreeIterator.Entry[]
entries()
Getter for the fielddirectory
.Get the location of the working file.protected byte[]
Get submodule id for given entry.protected String
Reads the target of a symlink as a string.Methods inherited from class org.eclipse.jgit.treewalk.WorkingTreeIterator
back, compareMetadata, current, eof, first, getCleanFilterCommand, getDirCacheIterator, getEntryAttributesNode, getEntryContentLength, getEntryLastModified, getEntryLastModifiedInstant, getEntryLength, getEolStreamType, getIndexFileMode, getOptions, getRepository, hasId, idBuffer, idOffset, idSubmodule, init, initRootIterator, isEntryIgnored, isEntryIgnored, isModeDifferent, isModified, isWorkTree, next, openEntryStream, reset, setDirCacheIterator, setWalkIgnoredDirectories, walksIgnoredDirectories
Methods inherited from class org.eclipse.jgit.treewalk.AbstractTreeIterator
createEmptyTreeIterator, createSubtreeIterator, ensurePathCapacity, findFile, findFile, getEntryFileMode, getEntryObjectId, getEntryObjectId, getEntryPathBuffer, getEntryPathHashCode, getEntryPathLength, getEntryPathString, getEntryRawMode, getName, getNameLength, getNameOffset, growPath, idEqual, needsStopWalk, pathCompare, pathCompare, pathCompare, skip, stopWalk, toString
-
Field Details
-
directory
the starting directory of this Iterator. All entries are located directly in this directory. -
fs
the file system abstraction which will be necessary to perform certain file system operations. -
fileModeStrategy
the strategy used to compute the FileMode for a FileEntry. Can be used to control things such as whether to recurse into a directory or create a gitlink.- Since:
- 4.3
-
-
Constructor Details
-
FileTreeIterator
Create a new iterator to traverse the work tree and its children.- Parameters:
repo
- the repository whose working tree will be scanned.
-
FileTreeIterator
Create a new iterator to traverse the work tree and its children.- Parameters:
repo
- the repository whose working tree will be scanned.fileModeStrategy
- the strategy to use to determine the FileMode for a FileEntry; controls gitlinks etc.- Since:
- 4.3
-
FileTreeIterator
Create a new iterator to traverse the given directory and its children.- Parameters:
root
- the starting directory. This directory should correspond to the root of the repository.fs
- the file system abstraction which will be necessary to perform certain file system operations.options
- working tree options to be used
-
FileTreeIterator
public FileTreeIterator(File root, FS fs, WorkingTreeOptions options, FileTreeIterator.FileModeStrategy fileModeStrategy) Create a new iterator to traverse the given directory and its children.- Parameters:
root
- the starting directory. This directory should correspond to the root of the repository.fs
- the file system abstraction which will be necessary to perform certain file system operations.options
- working tree options to be usedfileModeStrategy
- the strategy to use to determine the FileMode for a FileEntry; controls gitlinks etc.- Since:
- 4.3
-
FileTreeIterator
Create a new iterator to traverse a subdirectory.- Parameters:
p
- the parent iterator we were created from.root
- the subdirectory. This should be a directory contained within the parent directory.fs
- the file system abstraction which will be necessary to perform certain file system operations.- Since:
- 4.3
-
FileTreeIterator
protected FileTreeIterator(WorkingTreeIterator p, File root, FS fs, FileTreeIterator.FileModeStrategy fileModeStrategy) Create a new iterator to traverse a subdirectory, given the specified FileModeStrategy.- Parameters:
p
- the parent iterator we were created from.root
- the subdirectory. This should be a directory contained within the parent directoryfs
- the file system abstraction which will be necessary to perform certain file system operations.fileModeStrategy
- the strategy to use to determine the FileMode for a given FileEntry.- Since:
- 4.3
-
-
Method Details
-
createSubtreeIterator
public AbstractTreeIterator createSubtreeIterator(ObjectReader reader) throws IncorrectObjectTypeException, 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.IOException
- a loose object or pack file could not be read.
-
enterSubtree
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
.- Returns:
- a new iterator that walks over the current subtree.
- Since:
- 5.0
-
entries
-
getDirectory
Getter for the field
directory
.- Returns:
- The root directory of this iterator
-
getEntryFile
Get the location of the working file.- Returns:
- The location of the working file. This is the same as
new File(getDirectory(), getEntryPath())
but may be faster by reusing an internal File instance.
-
idSubmodule
Get submodule id for given entry.- Overrides:
idSubmodule
in classWorkingTreeIterator
- Parameters:
e
- aWorkingTreeIterator.Entry
object.- Returns:
- non-null submodule id
-
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.- Overrides:
readSymlinkTarget
in classWorkingTreeIterator
- 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
-