|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eclipse.jgit.treewalk.TreeWalk
public class TreeWalk
Walks one or more AbstractTreeIterator
s 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 Repository
are
permitted, even from concurrent threads.
Constructor Summary | |
---|---|
TreeWalk(ObjectReader or)
Create a new tree walker for a given repository. |
|
TreeWalk(Repository repo)
Create a new tree walker for a given repository. |
Method Summary | ||
---|---|---|
int |
addTree(AbstractTreeIterator p)
Add an already created tree iterator for walking. |
|
int |
addTree(AnyObjectId id)
Add an already existing tree object for walking. |
|
void |
enterSubtree()
Enter into the current subtree. |
|
static TreeWalk |
forPath(ObjectReader reader,
String path,
AnyObjectId... trees)
Open a tree walk and filter to exactly one path. |
|
static TreeWalk |
forPath(Repository db,
String path,
AnyObjectId... trees)
Open a tree walk and filter to exactly one path. |
|
static TreeWalk |
forPath(Repository db,
String path,
RevTree tree)
Open a tree walk and filter to exactly one path. |
|
int |
getDepth()
Get the current subtree depth of this walker. |
|
FileMode |
getFileMode(int nth)
Obtain the FileMode for the current entry. |
|
TreeFilter |
getFilter()
Get the currently configured filter. |
|
String |
getNameString()
Get the current entry's name within its parent tree. |
|
ObjectId |
getObjectId(int nth)
Obtain the ObjectId for the current entry. |
|
void |
getObjectId(MutableObjectId out,
int nth)
Obtain the ObjectId for the current entry. |
|
ObjectReader |
getObjectReader()
|
|
int |
getPathLength()
|
|
String |
getPathString()
Get the current entry's complete path. |
|
int |
getRawMode(int nth)
Obtain the raw FileMode bits for the current entry. |
|
byte[] |
getRawPath()
Get the current entry's complete path as a UTF-8 byte array. |
|
|
getTree(int nth,
Class<T> clazz)
Obtain the tree iterator for the current entry. |
|
int |
getTreeCount()
Get the number of trees known to this walker. |
|
boolean |
idEqual(int nthA,
int nthB)
Compare two tree's current ObjectId values for equality. |
|
int |
isPathPrefix(byte[] p,
int pLen)
Test if the supplied path matches the current entry's path. |
|
boolean |
isPathSuffix(byte[] p,
int pLen)
Test if the supplied path matches (being suffix of) the current entry's path. |
|
boolean |
isPostChildren()
Is the current entry a subtree returned after its children? |
|
boolean |
isPostOrderTraversal()
Does this walker return a tree entry after it exits the subtree? |
|
boolean |
isRecursive()
Is this walker automatically entering into subtrees? |
|
boolean |
isSubtree()
Is the current entry a subtree? |
|
boolean |
next()
Advance this walker to the next relevant entry. |
|
void |
release()
Release any resources used by this walker's reader. |
|
void |
reset()
Reset this walker so new tree iterators can be added to it. |
|
void |
reset(AnyObjectId... ids)
Reset this walker to run over a set of existing trees. |
|
void |
reset(AnyObjectId id)
Reset this walker to run over a single existing tree. |
|
void |
setFilter(TreeFilter newFilter)
Set the tree entry filter for this walker. |
|
void |
setPostOrderTraversal(boolean b)
Set the walker to return trees after their children. |
|
void |
setRecursive(boolean b)
Set the walker to enter (or not enter) subtrees automatically. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public TreeWalk(Repository repo)
repo
- the repository the walker will obtain data from.public TreeWalk(ObjectReader or)
or
- the reader the walker will obtain tree data from.Method Detail |
---|
public static TreeWalk forPath(ObjectReader reader, String path, AnyObjectId... trees) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException
The returned tree walk is already positioned on the requested path, so
the caller should not need to invoke next()
unless they are
looking for a possible directory/file name conflict.
reader
- the reader the walker will obtain tree data from.path
- single path to advance the tree walk instance into.trees
- one or more trees to walk through, all with the same root.
IOException
- reading a pack file or loose object failed.
CorruptObjectException
- an tree object could not be read as its data stream did not
appear to be a tree, or could not be inflated.
IncorrectObjectTypeException
- an object we expected to be a tree was not a tree.
MissingObjectException
- a tree object was not found.public static TreeWalk forPath(Repository db, String path, AnyObjectId... trees) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException
The returned tree walk is already positioned on the requested path, so
the caller should not need to invoke next()
unless they are
looking for a possible directory/file name conflict.
db
- repository to read tree object data from.path
- single path to advance the tree walk instance into.trees
- one or more trees to walk through, all with the same root.
IOException
- reading a pack file or loose object failed.
CorruptObjectException
- an tree object could not be read as its data stream did not
appear to be a tree, or could not be inflated.
IncorrectObjectTypeException
- an object we expected to be a tree was not a tree.
MissingObjectException
- a tree object was not found.public static TreeWalk forPath(Repository db, String path, RevTree tree) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException
The returned tree walk is already positioned on the requested path, so
the caller should not need to invoke next()
unless they are
looking for a possible directory/file name conflict.
db
- repository to read tree object data from.path
- single path to advance the tree walk instance into.tree
- the single tree to walk through.
IOException
- reading a pack file or loose object failed.
CorruptObjectException
- an tree object could not be read as its data stream did not
appear to be a tree, or could not be inflated.
IncorrectObjectTypeException
- an object we expected to be a tree was not a tree.
MissingObjectException
- a tree object was not found.public ObjectReader getObjectReader()
public void release()
A walker that has been released can be used again, but may need to be released after the subsequent usage.
public TreeFilter getFilter()
public void setFilter(TreeFilter newFilter)
Multiple filters may be combined by constructing an arbitrary tree of
AndTreeFilter
or OrTreeFilter
instances to
describe the boolean expression required by the application. Custom
filter implementations may also be constructed by applications.
Note that filters are not thread-safe and may not be shared by concurrent
TreeWalk instances. Every TreeWalk must be supplied its own unique
filter, unless the filter implementation specifically states it is (and
always will be) thread-safe. Callers may use TreeFilter.clone()
to create a unique filter tree for this TreeWalk instance.
newFilter
- the new filter. If null the special TreeFilter.ALL
filter will be used instead, as it matches every entry.AndTreeFilter
,
OrTreeFilter
public boolean isRecursive()
If the walker is recursive then the caller will not see a subtree node and instead will only receive file nodes in all relevant subtrees.
public void setRecursive(boolean b)
If recursive mode is enabled the walker will hide subtree nodes from the calling application and will produce only file level nodes. If a tree (directory) is deleted then all of the file level nodes will appear to be deleted, recursively, through as many levels as necessary to account for all entries.
b
- true to skip subtree nodes and only obtain files nodes.public boolean isPostOrderTraversal()
If post order traversal is enabled then the walker will return a subtree
after it has returned the last entry within that subtree. This may cause
a subtree to be seen by the application twice if isRecursive()
is false, as the application will see it once, call
enterSubtree()
, and then see it again as it leaves the subtree.
If an application does not enable isRecursive()
and it does not
call enterSubtree()
then the tree is returned only once as none
of the children were processed.
public void setPostOrderTraversal(boolean b)
b
- true to get trees after their children.isPostOrderTraversal()
public void reset()
public void reset(AnyObjectId id) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException
id
- the tree we need to parse. The walker will execute over this
single tree if the reset is successful.
MissingObjectException
- the given tree object does not exist in this repository.
IncorrectObjectTypeException
- the given object id does not denote a tree, but instead names
some other non-tree type of object. Note that commits are not
trees, even if they are sometimes called a "tree-ish".
CorruptObjectException
- the object claimed to be a tree, but its contents did not
appear to be a tree. The repository may have data corruption.
IOException
- a loose object or pack file could not be read.public void reset(AnyObjectId... ids) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException
ids
- the trees we need to parse. The walker will execute over this
many parallel trees if the reset is successful.
MissingObjectException
- the given tree object does not exist in this repository.
IncorrectObjectTypeException
- the given object id does not denote a tree, but instead names
some other non-tree type of object. Note that commits are not
trees, even if they are sometimes called a "tree-ish".
CorruptObjectException
- the object claimed to be a tree, but its contents did not
appear to be a tree. The repository may have data corruption.
IOException
- a loose object or pack file could not be read.public int addTree(AnyObjectId id) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException
The position of this tree is returned to the caller, in case the caller has lost track of the order they added the trees into the walker.
The tree must have the same root as existing trees in the walk.
id
- identity of the tree object the caller wants walked.
MissingObjectException
- the given tree object does not exist in this repository.
IncorrectObjectTypeException
- the given object id does not denote a tree, but instead names
some other non-tree type of object. Note that commits are not
trees, even if they are sometimes called a "tree-ish".
CorruptObjectException
- the object claimed to be a tree, but its contents did not
appear to be a tree. The repository may have data corruption.
IOException
- a loose object or pack file could not be read.public int addTree(AbstractTreeIterator p) throws CorruptObjectException
The position of this tree is returned to the caller, in case the caller has lost track of the order they added the trees into the walker.
The tree which the iterator operates on must have the same root as existing trees in the walk.
p
- 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.
CorruptObjectException
- the iterator was unable to obtain its first entry, due to
possible data corruption within the backing data store.public int getTreeCount()
public boolean next() throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException
MissingObjectException
- isRecursive()
was enabled, a subtree was found, but
the subtree object does not exist in this repository. The
repository may be missing objects.
IncorrectObjectTypeException
- isRecursive()
was enabled, a subtree was found, and
the subtree id does not denote a tree, but instead names some
other non-tree type of object. The repository may have data
corruption.
CorruptObjectException
- the contents of a tree did not appear to be a tree. The
repository may have data corruption.
IOException
- a loose object or pack file could not be read.public <T extends AbstractTreeIterator> T getTree(int nth, Class<T> clazz)
Entering into (or exiting out of) a subtree causes the current tree iterator instance to be changed for the nth tree. This allows the tree iterators to manage only one list of items, with the diving handled by recursive trees.
T
- type of the tree iterator expected by the caller.nth
- tree to obtain the current iterator of.clazz
- type of the tree iterator expected by the caller.
public int getRawMode(int nth)
FileMode
bits for the current entry.
Every added tree supplies mode bits, even if the tree does not contain
the current entry. In the latter case FileMode.MISSING
's mode
bits (0) are returned.
nth
- tree to obtain the mode bits from.
FileMode.fromBits(int)
public FileMode getFileMode(int nth)
FileMode
for the current entry.
Every added tree supplies a mode, even if the tree does not contain the
current entry. In the latter case FileMode.MISSING
is returned.
nth
- tree to obtain the mode from.
public ObjectId getObjectId(int nth)
Using this method to compare ObjectId values between trees of this walker
is very inefficient. Applications should try to use
idEqual(int, int)
or getObjectId(MutableObjectId, int)
whenever possible.
Every tree supplies an object id, even if the tree does not contain the
current entry. In the latter case ObjectId.zeroId()
is returned.
nth
- tree to obtain the object identifier from.
getObjectId(MutableObjectId, int)
,
idEqual(int, int)
public void getObjectId(MutableObjectId out, int nth)
Every tree supplies an object id, even if the tree does not contain the
current entry. In the latter case ObjectId.zeroId()
is supplied.
Applications should try to use idEqual(int, int)
when possible
as it avoids conversion overheads.
out
- buffer to copy the object id into.nth
- tree to obtain the object identifier from.idEqual(int, int)
public boolean idEqual(int nthA, int nthB)
nthA
- first tree to compare the object id from.nthB
- second tree to compare the object id from.
getObjectId(nthA).equals(getObjectId(nthB))
.getObjectId(int)
public String getNameString()
This method is not very efficient and is primarily meant for debugging and final output generation. Applications should try to avoid calling it, and if invoked do so only once per interesting entry, where the name is absolutely required for correct function.
public String getPathString()
This method is not very efficient and is primarily meant for debugging and final output generation. Applications should try to avoid calling it, and if invoked do so only once per interesting entry, where the name is absolutely required for correct function.
public byte[] getRawPath()
public int getPathLength()
public int isPathPrefix(byte[] p, int pLen)
This method tests that the supplied path is exactly equal to the current
entry, or is one of its parent directories. It is faster to use this
method then to use getPathString()
to first create a String
object, then test startsWith
or some other type of string
match function.
p
- path buffer to test. Callers should ensure the path does not
end with '/' prior to invocation.pLen
- number of bytes from buf
to test.
public boolean isPathSuffix(byte[] p, int pLen)
This method tests that the supplied path is exactly equal to the current
entry, or is relative to one of entry's parent directories. It is faster
to use this method then to use getPathString()
to first create
a String object, then test endsWith
or some other type of
string match function.
p
- path buffer to test.pLen
- number of bytes from buf
to test.
public int getDepth()
public boolean isSubtree()
This method is faster then testing the raw mode bits of all trees to see if any of them are a subtree. If at least one is a subtree then this method will return true.
enterSubtree()
will work on the current node.public boolean isPostChildren()
isPostOrderTraversal()
public void enterSubtree() throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException
If the current entry is a subtree this method arranges for its children to be returned before the next sibling following the subtree is returned.
MissingObjectException
- a subtree was found, but the subtree object does not exist in
this repository. The repository may be missing objects.
IncorrectObjectTypeException
- a subtree was found, and the subtree id does not denote a
tree, but instead names some other non-tree type of object.
The repository may have data corruption.
CorruptObjectException
- the contents of a tree did not appear to be a tree. The
repository may have data corruption.
IOException
- a loose object or pack file could not be read.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |