Class ObjectWalk
- All Implemented Interfaces:
AutoCloseable
,Iterable<RevCommit>
- Direct Known Subclasses:
DepthWalk.ObjectWalk
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
static interface
When walking over a tree and blob graph, objects are usually marked as seen as they are visited and this "seen" status is checked upon the next visit. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private ObjectWalk.TreeVisit
private ObjectWalk.TreeVisit
private static final int
private static final int
Indicates a non-RevCommit is inpendingObjects
.private ObjectFilter
private byte[]
private int
private BlockObjQueue
static final ObjectWalk.VisitationPolicy
The default visitation policy: causes all objects to be visited exactly once.private static final int
private static final int
private static final int
private static final int
private static final int
private ObjectWalk.VisitationPolicy
Fields inherited from class org.eclipse.jgit.revwalk.RevWalk
carryFlags, freeFlags, idBuffer, objects, PARSED, pending, queue, reader, RESERVED_FLAGS, REWRITE, roots, SEEN, shallowCommitsInitialized, TEMP_MARK, TOPO_DELAY, TOPO_QUEUED, UNINTERESTING
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new revision and object walker for a given repository.ObjectWalk
(Repository repo) Create a new revision and object walker for a given repository. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
void
Verify all interesting objects are available, and reachable.Deprecated.void
dispose()
Dispose all internal state and invalidate all RevObject instances.private static int
findObjectId
(byte[] buf, int ptr) Get the currently configured object filter.byte[]
Get the internal buffer holding the current path.int
Get the current object's path hash code.int
Get length of the path ingetPathBuffer()
.Get the current object's complete path.int
private void
growPathBuf
(int ptr) void
Mark an object or commit to start graph traversal from.private void
markTreeUninteresting
(RevTree tree) void
Mark an object to not produce in the output.next()
Pop the next most recent commit.Pop the next most recent object.private static int
parseMode
(byte[] buf, int startPtr, int recEndPtr, ObjectWalk.TreeVisit tv) private RevObject
private void
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
Sets the visitation policy to use during this walk.void
skipTree()
Skips the current tree such thatnextObject()
does not return any objects inside it.void
Select a single sorting strategy for the returned commits.void
Add or remove a sorting strategy for the returned commits.private int
Methods inherited from class org.eclipse.jgit.revwalk.RevWalk
allocFlag, assertNoCommitsMarkedStart, assertNotStarted, assumeShallow, carry, carry, carryFlagsImpl, close, createCommit, createReachabilityChecker, disposeFlag, freeFlag, getCachedBytes, getCachedBytes, getObjectReader, getRevFilter, getRevSort, getRewriteParents, getTreeFilter, hasRevSort, initializeShallowCommits, isFirstParent, 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, setFirstParent, setRetainBody, setRevFilter, setRewriteParents, setTreeFilter, toObjectWalkWithSameObjects
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
ID_SZ
private static final int ID_SZ- See Also:
-
TYPE_SHIFT
private static final int TYPE_SHIFT- See Also:
-
TYPE_TREE
private static final int TYPE_TREE- See Also:
-
TYPE_SYMLINK
private static final int TYPE_SYMLINK- See Also:
-
TYPE_FILE
private static final int TYPE_FILE- See Also:
-
TYPE_GITLINK
private static final int TYPE_GITLINK- See Also:
-
IN_PENDING
private static final int IN_PENDINGIndicates a non-RevCommit is inpendingObjects
.We can safely reuse
RevWalk.REWRITE
here for the same value as it is only set on RevCommit andpendingObjects
never has RevCommit instances inserted into it.- See Also:
-
SIMPLE_VISITATION_POLICY
The default visitation policy: causes all objects to be visited exactly once.- Since:
- 5.4
-
rootObjects
-
pendingObjects
-
objectFilter
-
freeVisit
-
currVisit
-
pathBuf
private byte[] pathBuf -
pathLen
private int pathLen -
boundary
private boolean boundary -
visitationPolicy
-
-
Constructor Details
-
ObjectWalk
Create a new revision and object walker for a given repository.- Parameters:
repo
- the repository the walker will obtain data from.
-
ObjectWalk
Create a new revision and object walker for a given repository.- Parameters:
or
- the reader the walker will obtain data from. The reader should be released by the caller when the walker is no longer required.
-
-
Method Details
-
createObjectReachabilityChecker
@Deprecated public final ObjectReachabilityChecker createObjectReachabilityChecker() throws IOExceptionDeprecated.useObjectReader#createObjectReachabilityChecker(ObjectWalk)
instead.Create an object reachability checker that will use bitmaps if possible. This reachability checker accepts any object as target. For checks exclusively between commits, seeRevWalk.createReachabilityChecker()
.- Returns:
- an object reachability checker, using bitmaps if possible.
- Throws:
IOException
- when the index fails to load.- Since:
- 5.8
-
markStart
public void markStart(RevObject o) throws MissingObjectException, IncorrectObjectTypeException, IOException Mark an object or commit to start graph traversal from.Callers are encouraged to use
RevWalk.parseAny(AnyObjectId)
instead ofRevWalk.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.- Parameters:
o
- the object to start traversing from. The object passed must be from this same revision walker.- Throws:
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 toRevWalk.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 aRevWalk.lookupAny(AnyObjectId, int)
call.IOException
- a pack file or loose object could not be read.
-
markUninteresting
public void markUninteresting(RevObject o) throws MissingObjectException, IncorrectObjectTypeException, IOException Mark an object to not produce in the output.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 ofRevWalk.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.- Parameters:
o
- the object to start traversing from. The object passed must be- Throws:
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 toRevWalk.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 aRevWalk.lookupAny(AnyObjectId, int)
call.IOException
- a pack file or loose object could not be read.
-
sort
Select a single sorting strategy for the returned commits.Disables all sorting strategies, then enables only the single strategy supplied by the caller.
-
sort
Add or remove a sorting strategy for the returned commits.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 overRevSort.COMMIT_TIME_DESC
, otherwise it cannot enforce its ordering. -
getObjectFilter
Get the currently configured object filter.- Returns:
- the current filter. Never null as a filter is always needed.
- Since:
- 4.0
-
setObjectFilter
Set the object filter for this walker. This filter affects the objects visited bynextObject()
. It does not affect the commits listed bynext()
.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.
- Parameters:
newFilter
- the new filter. If null the specialObjectFilter.ALL
filter will be used instead, as it matches every object.- Since:
- 4.0
-
setVisitationPolicy
Sets the visitation policy to use during this walk.- Parameters:
policy
- theVisitationPolicy
to use- Since:
- 5.4
-
next
Pop the next most recent commit.- Overrides:
next
in classRevWalk
- Returns:
- next most recent commit; null if traversal is over.
- Throws:
MissingObjectException
- one 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 more of the next commit's parents are not actually commit objects.IOException
- a pack file or loose object could not be read.
-
skipTree
public void skipTree()Skips the current tree such thatnextObject()
does not return any objects inside it. This should be called right afternextObject()
returns the tree.- Since:
- 5.4
-
nextObject
public RevObject nextObject() throws MissingObjectException, IncorrectObjectTypeException, IOExceptionPop the next most recent object.- Returns:
- next most recent object; null if traversal is over.
- Throws:
MissingObjectException
- one 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 more of the objects in a tree do not match the type indicated.IOException
- a pack file or loose object could not be read.
-
findObjectId
private static int findObjectId(byte[] buf, int ptr) -
parseMode
-
checkConnectivity
public void checkConnectivity() throws MissingObjectException, IncorrectObjectTypeException, IOExceptionVerify all interesting objects are available, and reachable.Callers should populate starting points and ending points with
markStart(RevObject)
andmarkUninteresting(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.
- Throws:
MissingObjectException
- one 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 more of the objects in a tree do not match the type indicated.IOException
- a pack file or loose object could not be read.
-
getPathString
Get the current object's complete path.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.
- 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. Null if the current entry has no path, such as for annotated tags or root level trees.
-
getTreeDepth
public int getTreeDepth()- Returns:
- the current traversal depth from the root tree object
- Since:
- 5.4
-
getPathHashCode
public int getPathHashCode()Get the current object's path hash code.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.
- Returns:
- path hash code; any integer may be returned.
-
getPathBuffer
public byte[] getPathBuffer()Get the internal buffer holding the current path.- Returns:
- the internal buffer holding the current path.
-
getPathLength
public int getPathLength()Get length of the path ingetPathBuffer()
.- Returns:
- length of the path in
getPathBuffer()
.
-
updatePathBuf
-
growPathBuf
private void growPathBuf(int ptr) -
dispose
public void dispose()Dispose all internal state and invalidate all RevObject instances.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.
-
reset
protected void reset(int retainFlags) Resets internal state and allows this instance to be used again.Unlike
RevWalk.dispose()
previously acquired RevObject (and RevCommit) instances are not invalidated. RevFlag instances are not invalidated, but are removed from all RevObjects. The value offirstParent
is retained. -
addObject
-
markTreeUninteresting
private void markTreeUninteresting(RevTree tree) throws MissingObjectException, IncorrectObjectTypeException, IOException -
pushTree
private RevObject pushTree(RevObject obj) throws LargeObjectException, MissingObjectException, IncorrectObjectTypeException, IOException -
releaseTreeVisit
-
ObjectReader#createObjectReachabilityChecker(ObjectWalk)
instead.