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
-
public class FileTreeIterator extends WorkingTreeIterator
Working directory iterator for standard Java IO.This iterator uses the standard
java.io
package to read the specified working directory as part of aTreeWalk
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FileTreeIterator.DefaultFileModeStrategy
A default implementation of a FileModeStrategy; defaults to treating nested .git directories as gitlinks, etc.static class
FileTreeIterator.FileEntry
Wrapper for a standard Java IO filestatic interface
FileTreeIterator.FileModeStrategy
An interface representing the methods used to determine the FileMode for a FileEntry.static class
FileTreeIterator.NoGitlinksStrategy
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
Fields Modifier and Type Field Description protected File
directory
the starting directory of this Iterator.protected FileTreeIterator.FileModeStrategy
fileModeStrategy
the strategy used to compute the FileMode for a FileEntry.protected FS
fs
the file system abstraction which will be necessary to perform certain file system operations.-
Fields inherited from class org.eclipse.jgit.treewalk.WorkingTreeIterator
EOF, repository
-
Fields inherited from class org.eclipse.jgit.treewalk.AbstractTreeIterator
attributesNode, DEFAULT_PATH_SIZE, mode, parent, path, pathLen, pathOffset, zeroid
-
-
Constructor Summary
Constructors Modifier Constructor Description FileTreeIterator(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AbstractTreeIterator
createSubtreeIterator(ObjectReader reader)
Create a new iterator for the current entry's subtree.protected AbstractTreeIterator
enterSubtree()
Create a new iterator for the current entry's subtree.File
getDirectory()
Getter for the fielddirectory
.File
getEntryFile()
Get the location of the working file.protected byte[]
idSubmodule(WorkingTreeIterator.Entry e)
Get submodule id for given entry.protected String
readSymlinkTarget(WorkingTreeIterator.Entry entry)
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, skip, stopWalk, toString
-
-
-
-
Field Detail
-
directory
protected final File directory
the starting directory of this Iterator. All entries are located directly in this directory.
-
fs
protected final FS fs
the file system abstraction which will be necessary to perform certain file system operations.
-
fileModeStrategy
protected final FileTreeIterator.FileModeStrategy 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 Detail
-
FileTreeIterator
public FileTreeIterator(Repository repo)
Create a new iterator to traverse the work tree and its children.- Parameters:
repo
- the repository whose working tree will be scanned.
-
FileTreeIterator
public FileTreeIterator(Repository repo, FileTreeIterator.FileModeStrategy fileModeStrategy)
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
public FileTreeIterator(File root, FS fs, WorkingTreeOptions options)
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
protected FileTreeIterator(FileTreeIterator p, File root, FS fs)
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 Detail
-
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
protected AbstractTreeIterator 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
-
getDirectory
public File getDirectory()
Getter for the field
directory
.- Returns:
- The root directory of this iterator
-
getEntryFile
public File 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
protected byte[] idSubmodule(WorkingTreeIterator.Entry e)
Get submodule id for given entry.- Overrides:
idSubmodule
in classWorkingTreeIterator
- Parameters:
e
- aWorkingTreeIterator.Entry
object.- Returns:
- non-null submodule id
-
readSymlinkTarget
protected String readSymlinkTarget(WorkingTreeIterator.Entry entry) throws IOException
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
-
-