org.eclipse.jgit.revwalk
Class ObjectWalk

java.lang.Object
  extended by org.eclipse.jgit.revwalk.RevWalk
      extended by org.eclipse.jgit.revwalk.ObjectWalk
All Implemented Interfaces:
java.lang.Iterable<RevCommit>

public class ObjectWalk
extends RevWalk

Specialized subclass of RevWalk to include trees, blobs and tags.

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 Summary
ObjectWalk(Repository repo)
          Create a new revision and object walker for a given repository.
 
Method Summary
 void checkConnectivity()
          Verify all interesting objects are available, and reachable.
 void dispose()
          Dispose all internal state and invalidate all RevObject instances.
 java.lang.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.
 
Methods inherited from class org.eclipse.jgit.revwalk.RevWalk
assertNotStarted, carry, carry, createCommit, disposeFlag, getRepository, getRevFilter, getRevSort, getTreeFilter, hasRevSort, isMergedInto, isRetainBody, iterator, lookupAny, lookupBlob, lookupCommit, lookupTree, markStart, markStart, markUninteresting, newFlag, parseAny, parseBody, parseCommit, parseHeaders, parseTree, reset, resetRetain, resetRetain, setRetainBody, setRevFilter, setTreeFilter, sort, sort
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectWalk

public ObjectWalk(Repository repo)
Create a new revision and object walker for a given repository.

Parameters:
repo - the repository the walker will obtain data from.
Method Detail

markStart

public void markStart(RevObject o)
               throws MissingObjectException,
                      IncorrectObjectTypeException,
                      java.io.IOException
Mark an object or commit to start graph traversal from.

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.

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 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.
java.io.IOException - a pack file or loose object could not be read.

markUninteresting

public void markUninteresting(RevObject o)
                       throws MissingObjectException,
                              IncorrectObjectTypeException,
                              java.io.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 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.

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 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.
java.io.IOException - a pack file or loose object could not be read.

next

public RevCommit next()
               throws MissingObjectException,
                      IncorrectObjectTypeException,
                      java.io.IOException
Description copied from class: RevWalk
Pop the next most recent commit.

Overrides:
next in class RevWalk
Returns:
next most recent commit; null if traversal is over.
Throws:
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.
java.io.IOException - a pack file or loose object could not be read.

nextObject

public RevObject nextObject()
                     throws MissingObjectException,
                            IncorrectObjectTypeException,
                            java.io.IOException
Pop the next most recent object.

Returns:
next most recent object; null if traversal is over.
Throws:
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.
java.io.IOException - a pack file or loose object could not be read.

checkConnectivity

public void checkConnectivity()
                       throws MissingObjectException,
                              IncorrectObjectTypeException,
                              java.io.IOException
Verify all interesting objects are available, and reachable.

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.

Throws:
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.
java.io.IOException - a pack file or loose object could not be read.

getPathString

public java.lang.String 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.

dispose

public void dispose()
Description copied from class: RevWalk
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.

Overrides:
dispose in class RevWalk

reset

protected void reset(int retainFlags)
Description copied from class: RevWalk
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.

Overrides:
reset in class RevWalk
Parameters:
retainFlags - application flags that should not be cleared from existing commit objects.