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

public Class TreeWalk

extends Object
implements AutoCloseable, AttributesProvider
Class Inheritance
All Implemented Interfaces
org.eclipse.jgit.attributes.AttributesProvider, java.lang.AutoCloseable
Known Direct Subclasses
org.eclipse.jgit.treewalk.NameConflictTreeWalk
Static Imports
java.nio.charset.StandardCharsets.UTF_8

Walks one or more org.eclipse.jgit.treewalk.AbstractTreeIterators in parallel.

This class can perform n-way differences across as many trees as necessary.

Each tree added must have the same root as existing trees in the walk.

A TreeWalk instance can only be used once to generate results. Running a second time requires creating a new TreeWalk instance, or invoking reset() and adding new trees before starting again. Resetting an existing instance may be faster for some applications as some internal buffers may be recycled.

TreeWalk instances are not thread-safe. Applications must either restrict usage of a TreeWalk instance to a single thread, or implement their own synchronization at a higher level.

Multiple simultaneous TreeWalk instances per org.eclipse.jgit.lib.Repository are permitted, even from concurrent threads.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
TreeWalk.OperationType

Type of operation to retrieve git attributes for.

Field Summary

Modifier and TypeField and Description
private boolean
private AttributesHandler[]
attributesHandlers

Cached attributes handler; per tree.

private AttributesNodeProvider
private Attributes[]
attrs

Cached attributes for the current entry; per tree.

private final boolean
private Config
pack-priv AbstractTreeIterator
pack-priv int
private TreeFilter
private Set<String>
private Map<String, String>
filterCommandsByNameDotType

The filter command as defined in gitattributes.

private int
headIndex

Can be set to identify the tree to use for getAttributes().

private final MutableObjectId
private static final AbstractTreeIterator[]
private TreeWalk.OperationType
operationType

Type of operation you want to retrieve the git attributes for.

private boolean
private boolean
private final ObjectReader
private boolean
pack-priv AbstractTreeIterator[]

Constructor Summary

AccessConstructor and Description
public
TreeWalk(Repository
the repository the walker will obtain data from. An ObjectReader will be created by the walker, and will be closed when the walker is closed.
repo
)

Create a new tree walker for a given repository.

public
TreeWalk(Repository
the repository the walker will obtain data from. An ObjectReader will be created by the walker, and will be closed when the walker is closed.
repo
,
ObjectReader
the reader the walker will obtain tree data from. The reader is not closed when the walker is closed.
or
)

Create a new tree walker for a given repository.

public
TreeWalk(ObjectReader
the reader the walker will obtain tree data from. The reader is not closed when the walker is closed.
or
)

Create a new tree walker for a given repository.

private
TreeWalk(final Repository repo, final ObjectReader or, final boolean closeReader)

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

position of this tree within the walker.
addTree
(AnyObjectId
identity of the tree object the caller wants walked.
id
)

Add an already existing tree object for walking.

public int

Returns:

position of this tree within the walker.
addTree
(AbstractTreeIterator
an iterator to walk over. The iterator should be new, with no parent, and should still be positioned before the first entry. The tree which the iterator operates on must have the same root as other trees in the walk.
p
)

Add an already created tree iterator for walking.

public void
close()

Implements java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources.

public void
enterSubtree()

Enter into the current subtree.

pack-priv void
public static TreeWalk

Returns:

a new tree walk configured for exactly this one path; null if no path was found in any of the trees.
forPath
(final ObjectReader
the reader the walker will obtain tree data from.
reader
,
final String
single path to advance the tree walk instance into.
path
,
final AnyObjectId...
one or more trees to walk through, all with the same root.
trees
)

Open a tree walk and filter to exactly one path.

public static TreeWalk

Returns:

a new tree walk configured for exactly this one path; null if no path was found in any of the trees.
forPath
(final Repository
repository to read config data and org.eclipse.jgit.attributes.AttributesNodeProvider from.
repo
,
final ObjectReader
the reader the walker will obtain tree data from.
reader
,
final String
single path to advance the tree walk instance into.
path
,
final AnyObjectId...
one or more trees to walk through, all with the same root.
trees
)

Open a tree walk and filter to exactly one path.

public static TreeWalk

Returns:

a new tree walk configured for exactly this one path; null if no path was found in any of the trees.
forPath
(final Repository
repository to read tree object data from.
db
,
final String
single path to advance the tree walk instance into.
path
,
final AnyObjectId...
one or more trees to walk through, all with the same root.
trees
)

Open a tree walk and filter to exactly one path.

public static TreeWalk

Returns:

a new tree walk configured for exactly this one path; null if no path was found in any of the trees.
forPath
(final Repository
repository to read tree object data from.
db
,
final String
single path to advance the tree walk instance into.
path
,
final RevTree
the single tree to walk through.
tree
)

Open a tree walk and filter to exactly one path.

public Attributes
getAttributes()

Implements org.eclipse.jgit.attributes.AttributesProvider.getAttributes.

Get attributes

Retrieve the git attributes for the current entry.

public Attributes

Returns:

the attributes
getAttributes
(int
of the tree to use as base for the attributes
index
)

Retrieves the git attributes based on the given tree.

public AttributesNodeProvider
public CoreConfig.EolStreamType

Returns:

the EOL stream type of the current entry using the config and getAttributes(). Note that this method may return null if the org.eclipse.jgit.treewalk.TreeWalk is not based on a working tree
getCheckoutEolStreamType
(int
index of the tree the check-out is to be from
tree
)

Get the EOL stream type of the current entry for checking out using the config and getAttributes().

public int

Returns:

the current subtree depth of this walker.
getDepth
()

Get the current subtree depth of this walker.

public CoreConfig.EolStreamType

Returns:

the EOL stream type of the current entry using the config and getAttributes(). Note that this method may return null if the org.eclipse.jgit.treewalk.TreeWalk is not based on a working tree
getEolStreamType
(TreeWalk.OperationType
the operationtype (checkin/checkout) which should be used
opType
)

Get the EOL stream type of the current entry using the config and getAttributes().

public FileMode

Returns:

mode for the current entry of the nth tree.
getFileMode
(int
tree to obtain the mode from.
nth
)

Obtain the org.eclipse.jgit.lib.FileMode for the current entry.

public FileMode

Returns:

mode for the current entry of the currentHead tree.
getFileMode
()

Obtain the org.eclipse.jgit.lib.FileMode for the current entry on the currentHead tree

public TreeFilter

Returns:

the current filter. Never null as a filter is always needed.
getFilter
()

Get the currently configured filter.

public String

Returns:

a filter command
getFilterCommand
(String
which type of filterCommand should be executed. E.g. "clean", "smudge". For "smudge" consider using {getSmudgeCommand(int) instead.
filterCommandType
)

Inspect config and attributes to return a filtercommand applicable for the current path.

private String

Returns:

the definition of the command to be executed for this filter driver and filter command
getFilterCommandDefinition
(String
The name of the filter driver as it is referenced in the gitattributes file. E.g. "lfs". For each filter driver there may be many commands defined in the .gitconfig
filterDriverName
,
String
The type of the filter command for a specific filter driver. May be "clean" or "smudge".
filterCommandType
)

Get the filter command how it is defined in gitconfig.

public String

Returns:

name of the current entry within the parent tree (or directory). The name never includes a '/'.
getNameString
()

Get the current entry's name within its parent tree.

public ObjectId

Returns:

object identifier for the current tree entry.
getObjectId
(int
tree to obtain the object identifier from.
nth
)

Obtain the ObjectId for the current entry.

public void
getObjectId(MutableObjectId
buffer to copy the object id into.
out
,
int
tree to obtain the object identifier from.
nth
)

Obtain the ObjectId for the current entry.

public ObjectReader

Returns:

the reader this walker is using to load objects.
getObjectReader
()

Get the reader this walker is using to load objects.

public TreeWalk.OperationType
public int

Returns:

The path length of the current entry.
getPathLength
()

Get the path length of the current entry.

public String

Returns:

complete path of the current entry, from the root of the repository. If the current entry is in a subtree there will be at least one '/' in the returned string.
getPathString
()

Get the current entry's complete path.

public int

Returns:

mode bits for the current entry of the nth tree.
getRawMode
(int
tree to obtain the mode bits from.
nth
)

Obtain the raw org.eclipse.jgit.lib.FileMode bits for the current entry.

public byte[]

Returns:

complete path of the current entry, from the root of the repository. If the current entry is in a subtree there will be at least one '/' in the returned string.
getRawPath
()

Get the current entry's complete path as a UTF-8 byte array.

public String

Returns:

a filter command
getSmudgeCommand
(int
of the tree the item to be smudged is in
index
)

Inspect config and attributes to return a filtercommand applicable for the current path.

public String

Returns:

a filter command
getSmudgeCommand
(Attributes
to use
attributes
)

Inspect config and attributes to return a filtercommand applicable for the current path.

public <
Type of returned AbstractTreeIterator
T extends AbstractTreeIterator
>
T

Returns:

r the current iterator of the requested type; null if the tree has no entry to match the current path.
getTree
(final int
tree to obtain the current iterator of.
nth
,
final Class<T>
type of the tree iterator expected by the caller.
clazz
)

Obtain the tree iterator for the current entry.

public <
a tree type.
T extends AbstractTreeIterator
>
T

Returns:

the tree of that type or null if none is present.
getTree
(Class<T>
of the tree to be queried
type
)

Get the tree of that type.

public int

Returns:

the total number of trees this walker is iterating over.
getTreeCount
()

Get the number of trees known to this walker.

public boolean

Returns:

result of getObjectId(nthA).equals(getObjectId(nthB)).
idEqual
(int
first tree to compare the object id from.
nthA
,
int
second tree to compare the object id from.
nthB
)

Compare two tree's current ObjectId values for equality.

public int

Returns:

-1 if the current path is a parent to p; 0 if p matches the current path; 1 if the current path is different and will never match again on this tree walk.
isPathMatch
(byte[]
path buffer to test. Callers should ensure the path does not end with '/' prior to invocation.
p
,
int
number of bytes from buf to test.
pLen
)

Test if the supplied path matches the current entry's path.

public int

Returns:

< 0 if p is before the current path; 0 if p matches the current path; 1 if the current path is past p and p will never match again on this tree walk.
isPathPrefix
(byte[]
path buffer to test. Callers should ensure the path does not end with '/' prior to invocation.
p
,
int
number of bytes from buf to test.
pLen
)

Test if the supplied path matches the current entry's path.

public boolean

Returns:

true if p is suffix of the current path; false if otherwise
isPathSuffix
(byte[]
path buffer to test.
p
,
int
number of bytes from buf to test.
pLen
)

Test if the supplied path matches (being suffix of) the current entry's path.

public boolean

Returns:

true if the current node is a tree that has been returned after its children were already processed.
isPostChildren
()

Is the current entry a subtree returned after its children?

public boolean

Returns:

true if subtrees are returned after entries within the subtree.
isPostOrderTraversal
()

Does this walker return a tree entry after it exits the subtree?

public boolean

Returns:

true if automatically entering subtrees is enabled.
isRecursive
()

Is this walker automatically entering into subtrees?

public boolean

Returns:

true if enterSubtree() will work on the current node.
isSubtree
()

Is the current entry a subtree?

pack-priv AbstractTreeIterator

Returns:

the smallest tree iterator available.
min
()

Returns an AbstractTreeIterator from trees with the smallest name, and sets its matches field.

public boolean

Returns:

true if there is an entry available; false if all entries have been walked and the walk of this set of tree iterators is over.
next
()

Advance this walker to the next relevant entry.

private CanonicalTreeParser
pack-priv static String
pack-priv static String
pathOf(byte[] buf, int pos, int end)

pack-priv void
public void
reset()

Reset this walker so new tree iterators can be added to it.

public void
reset(AnyObjectId
the tree we need to parse. The walker will execute over this single tree if the reset is successful.
id
)

Reset this walker to run over a single existing tree.

public void
reset(AnyObjectId...
the trees we need to parse. The walker will execute over this many parallel trees if the reset is successful.
ids
)

Reset this walker to run over a set of existing trees.

public void
public void
setFilter(TreeFilter
the new filter. If null the special org.eclipse.jgit.treewalk.filter.TreeFilter#ALL filter will be used instead, as it matches every entry.
newFilter
)

Set the tree entry filter for this walker.

public void
setHead(int
of the tree to use as head
index
)

Identifies the tree at the given index as the head tree.

public void
setOperationType(TreeWalk.OperationType operationType)

Set the operation type of this walk

public void
setPostOrderTraversal(boolean
true to get trees after their children.
b
)

Set the walker to return trees after their children.

public void
setRecursive(boolean
true to skip subtree nodes and only obtain files nodes.
b
)

Set the walker to enter (or not enter) subtrees automatically.

pack-priv void
pack-priv void
stopWalk()

Notify iterators the walk is aborting.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait