public class ObjectWalk extends RevWalk
Unlike RevWalk this subclass is able to remember starting roots that include
annotated tags, or arbitrary trees or blobs. Once commit generation is
complete and all commits have been popped by the application, individual
annotated tag, tree and blob objects can be popped through the additional
method nextObject()
.
Tree and blob objects reachable from interesting commits are automatically
scheduled for inclusion in the results of nextObject()
, returning
each object exactly once. Objects are sorted and returned according to the
the commits that reference them and the order they appear within a tree.
Ordering can be affected by changing the RevSort
used to order the
commits that are returned first.
Constructor and Description |
---|
ObjectWalk(ObjectReader or)
Create a new revision and object walker for a given repository.
|
ObjectWalk(Repository repo)
Create a new revision and object walker for a given repository.
|
Modifier and Type | Method and Description |
---|---|
void |
checkConnectivity()
Verify all interesting objects are available, and reachable.
|
void |
dispose()
Dispose all internal state and invalidate all RevObject instances.
|
ObjectFilter |
getObjectFilter()
Get the currently configured object filter.
|
byte[] |
getPathBuffer() |
int |
getPathHashCode()
Get the current object's path hash code.
|
int |
getPathLength() |
String |
getPathString()
Get the current object's complete path.
|
void |
markStart(RevObject o)
Mark an object or commit to start graph traversal from.
|
void |
markUninteresting(RevObject o)
Mark an object to not produce in the output.
|
RevCommit |
next()
Pop the next most recent commit.
|
RevObject |
nextObject()
Pop the next most recent object.
|
protected void |
reset(int retainFlags)
Resets internal state and allows this instance to be used again.
|
void |
setObjectFilter(ObjectFilter newFilter)
Set the object filter for this walker.
|
void |
sort(RevSort s)
Select a single sorting strategy for the returned commits.
|
void |
sort(RevSort s,
boolean use)
Add or remove a sorting strategy for the returned commits.
|
assertNotStarted, assumeShallow, carry, carry, close, createCommit, disposeFlag, getObjectReader, getRevFilter, getRevSort, getTreeFilter, hasRevSort, isMergedInto, isRetainBody, iterator, lookupAny, lookupBlob, lookupCommit, lookupOrNull, lookupTag, lookupTree, markStart, markStart, markUninteresting, newFlag, parseAny, parseAny, parseBody, parseCommit, parseHeaders, parseTag, parseTree, peel, reset, resetRetain, resetRetain, retainOnReset, retainOnReset, setRetainBody, setRevFilter, setRewriteParents, setTreeFilter, toObjectWalkWithSameObjects
public ObjectWalk(Repository repo)
repo
- the repository the walker will obtain data from.public ObjectWalk(ObjectReader or)
or
- the reader the walker will obtain data from. The reader should
be released by the caller when the walker is no longer
required.public void markStart(RevObject o) throws MissingObjectException, IncorrectObjectTypeException, IOException
Callers are encouraged to use RevWalk.parseAny(AnyObjectId)
instead of RevWalk.lookupAny(AnyObjectId, int)
, as this method
requires the object to be parsed before it can be added as a root for the
traversal.
The method will automatically parse an unparsed object, but error handling may be more difficult for the application to explain why a RevObject is not actually valid. The object pool of this walker would also be 'poisoned' by the invalid RevObject.
This method will automatically call RevWalk.markStart(RevCommit)
if passed RevCommit instance, or a RevTag that directly (or indirectly)
references a RevCommit.
o
- the object to start traversing from. The object passed must be
from this same revision walker.MissingObjectException
- the object supplied is not available from the object
database. This usually indicates the supplied object is
invalid, but the reference was constructed during an earlier
invocation to RevWalk.lookupAny(AnyObjectId, int)
.IncorrectObjectTypeException
- the object was not parsed yet and it was discovered during
parsing that it is not actually the type of the instance
passed in. This usually indicates the caller used the wrong
type in a RevWalk.lookupAny(AnyObjectId, int)
call.IOException
- a pack file or loose object could not be read.public void markUninteresting(RevObject o) throws MissingObjectException, IncorrectObjectTypeException, IOException
Uninteresting objects denote not just themselves but also their entire reachable chain, back until the merge base of an uninteresting commit and an otherwise interesting commit.
Callers are encouraged to use RevWalk.parseAny(AnyObjectId)
instead of RevWalk.lookupAny(AnyObjectId, int)
, as this method
requires the object to be parsed before it can be added as a root for the
traversal.
The method will automatically parse an unparsed object, but error handling may be more difficult for the application to explain why a RevObject is not actually valid. The object pool of this walker would also be 'poisoned' by the invalid RevObject.
This method will automatically call RevWalk.markStart(RevCommit)
if passed RevCommit instance, or a RevTag that directly (or indirectly)
references a RevCommit.
o
- the object to start traversing from. The object passed must beMissingObjectException
- the object supplied is not available from the object
database. This usually indicates the supplied object is
invalid, but the reference was constructed during an earlier
invocation to RevWalk.lookupAny(AnyObjectId, int)
.IncorrectObjectTypeException
- the object was not parsed yet and it was discovered during
parsing that it is not actually the type of the instance
passed in. This usually indicates the caller used the wrong
type in a RevWalk.lookupAny(AnyObjectId, int)
call.IOException
- a pack file or loose object could not be read.public void sort(RevSort s)
RevWalk
Disables all sorting strategies, then enables only the single strategy supplied by the caller.
public void sort(RevSort s, boolean use)
RevWalk
Multiple strategies can be applied at once, in which case some strategies
may take precedence over others. As an example, RevSort.TOPO
must
take precedence over RevSort.COMMIT_TIME_DESC
, otherwise it
cannot enforce its ordering.
public ObjectFilter getObjectFilter()
public void setObjectFilter(ObjectFilter newFilter)
nextObject()
. It does not affect the commits
listed by next()
.
If the filter returns false for an object, then that object is skipped and objects reachable from it are not enqueued to be walked recursively. This can be used to speed up the object walk by skipping subtrees that are known to be uninteresting.
newFilter
- the new filter. If null the special ObjectFilter.ALL
filter will be used instead, as it matches every object.public RevCommit next() throws MissingObjectException, IncorrectObjectTypeException, IOException
RevWalk
next
in class RevWalk
MissingObjectException
- one or or more of the next commit's parents are not available
from the object database, but were thought to be candidates
for traversal. This usually indicates a broken link.IncorrectObjectTypeException
- one or or more of the next commit's parents are not actually
commit objects.IOException
- a pack file or loose object could not be read.public RevObject nextObject() throws MissingObjectException, IncorrectObjectTypeException, IOException
MissingObjectException
- one or or more of the next objects are not available from the
object database, but were thought to be candidates for
traversal. This usually indicates a broken link.IncorrectObjectTypeException
- one or or more of the objects in a tree do not match the type
indicated.IOException
- a pack file or loose object could not be read.public void checkConnectivity() throws MissingObjectException, IncorrectObjectTypeException, IOException
Callers should populate starting points and ending points with
markStart(RevObject)
and markUninteresting(RevObject)
and then use this method to verify all objects between those two points
exist in the repository and are readable.
This method returns successfully if everything is connected; it throws an exception if there is a connectivity problem. The exception message provides some detail about the connectivity failure.
MissingObjectException
- one or or more of the next objects are not available from the
object database, but were thought to be candidates for
traversal. This usually indicates a broken link.IncorrectObjectTypeException
- one or or more of the objects in a tree do not match the type
indicated.IOException
- a pack file or loose object could not be read.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 int getPathHashCode()
This method computes a hash code on the fly for this path, the hash is suitable to cluster objects that may have similar paths together.
public byte[] getPathBuffer()
public int getPathLength()
getPathBuffer()
.public void dispose()
RevWalk
All RevObject (and thus RevCommit, etc.) instances previously acquired from this RevWalk are invalidated by a dispose call. Applications must not retain or use RevObject instances obtained prior to the dispose call. All RevFlag instances are also invalidated, and must not be reused.
protected void reset(int retainFlags)
RevWalk
Unlike RevWalk.dispose()
previously acquired RevObject (and RevCommit)
instances are not invalidated. RevFlag instances are not invalidated, but
are removed from all RevObjects.
Copyright © 2015 Eclipse JGit Project. All rights reserved.