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

public Class RevWalk

extends Object
implements Iterable<RevCommit>, AutoCloseable
Class Inheritance
All Implemented Interfaces
java.lang.AutoCloseable, java.lang.Iterable
Known Direct Subclasses
org.eclipse.jgit.blame.ReverseWalk, org.eclipse.jgit.revplot.PlotWalk, org.eclipse.jgit.revwalk.DepthWalk.RevWalk, org.eclipse.jgit.revwalk.ObjectWalk
Static Imports
org.eclipse.jgit.internal.storage.commitgraph.CommitGraph.EMPTY

Walks a commit graph and produces the matching commits in order.

A RevWalk instance can only be used once to generate results. Running a second time requires creating a new RevWalk instance, or invoking reset() before starting again. Resetting an existing instance may be faster for some applications as commit body parsing can be avoided on the later invocations.

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

Multiple simultaneous RevWalk instances per org.eclipse.jgit.lib.Repository are permitted, even from concurrent threads. Equality of org.eclipse.jgit.revwalk.RevCommits from two different RevWalk instances is never true, even if their org.eclipse.jgit.lib.ObjectIds are equal (and thus they describe the same commit).

The offered iterator is over the list of RevCommits described by the configuration of this instance. Applications should restrict themselves to using either the provided Iterator or next(), but never use both on the same RevWalk at the same time. The Iterator may buffer RevCommits, while next() does not.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum

Field Summary

Modifier and TypeField and Description
private static final int
pack-priv int
private final boolean
private CommitGraph
private int
private RevFilter
private boolean
pack-priv int
pack-priv final MutableObjectId
private static final int
pack-priv ObjectIdOwnerMap<RevObject>
pack-priv static final int
PARSED

Set on objects whose important header data has been loaded.

pack-priv Generator
pack-priv AbstractRevQueue
pack-priv final ObjectReader
pack-priv static final int
RESERVED_FLAGS

Number of flag bits we keep internal for our own use.

private boolean
private int
pack-priv static final int
REWRITE

Set on a RevCommit that can collapse out of the history.

private boolean
pack-priv final ArrayList<RevCommit>
pack-priv static final int
SEEN

Set on RevCommit instances added to our pending queue.

pack-priv boolean
private final EnumSet<RevSort>
pack-priv static final int
TEMP_MARK

Temporary mark for use within generators or filters.

pack-priv static final int
TOPO_DELAY

Temporary mark for use within TopoSortGenerator.

pack-priv static final int
TOPO_QUEUED

Temporary mark for use within TopoNonIntermixSortGenerator.

pack-priv static final int
TREE_REV_FILTER_APPLIED

Set on a RevCommit when a TreeRevFilter has been applied.

private TreeFilter
pack-priv static final int
UNINTERESTING

Set on RevCommit instances the caller does not want output.

Constructor Summary

AccessConstructor and Description
public
RevWalk(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 revision walker for a given repository.

public
RevWalk(ObjectReader
the reader the walker will obtain data from. The reader is not closed when the walker is closed (but is closed by dispose().
or
)

Create a new revision walker for a given repository.

pack-priv
RevWalk(ObjectReader or, boolean closeReader)

Method Summary

Modifier and TypeMethod and Description
pack-priv int
protected void
assertNoCommitsMarkedStart()

Throws an exception if any commits have been marked as start.

protected void
assertNotStarted()

Throws an exception if we have started producing output.

public void
assumeShallow(Collection<? extends ObjectId>
commits that should be treated as shallow commits, in addition to any commits already known to be shallow by the repository.
ids
)

Assume additional commits are shallow (have no parents).

public void
carry(RevFlag
the flag to carry onto parents, if set on a descendant.
flag
)

Automatically carry a flag from a child commit to its parents.

public void
carry(Collection<RevFlag>
the flags to carry onto parents, if set on a descendant.
set
)

Automatically carry flags from a child commit to its parents.

pack-priv void
public void
close()

Implements java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources.

pack-priv CommitGraph

Returns:

the commit-graph. Never null.
commitGraph
()

Get the commit-graph.

protected RevCommit

Returns:

a new unparsed reference for the object.
createCommit
(AnyObjectId
the object this walker requires a commit reference for.
id
)

Construct a new unparsed commit for the given object.

private RevCommit
createCommit(AnyObjectId id, int graphPos)

public void
dispose()

Dispose all internal state and invalidate all RevObject instances.

public void
disposeFlag(RevFlag
the to recycle.
flag
)

Allow a flag to be recycled for a different use.

private void
pack-priv void
freeFlag(int mask)

pack-priv byte[]
pack-priv byte[]
private Set<RevCommit>
getCommitsMergedInto(RevCommit needle, Collection<RevCommit> haystacks, Enum<E extends Enum<E>> returnStrategy, ProgressMonitor monitor)

public List<Ref>

Returns:

list of refs that are reachable from commit.
getMergedInto
(RevCommit
commit the caller thinks is reachable from refs.
commit
,
Collection<Ref>
refs to start iteration from, and which is most likely a descendant (child) of commit.
refs
)

Determine the Refs into which a commit is merged.

public List<Ref>

Returns:

list of refs that are reachable from commit.
getMergedInto
(RevCommit
commit the caller thinks is reachable from refs.
commit
,
Collection<Ref>
refs to start iteration from, and which is most likely a descendant (child) of commit.
refs
,
ProgressMonitor
the callback for progress and cancellation
monitor
)

Determine the Refs into which a commit is merged.

private List<Ref>
getMergedInto(RevCommit needle, Collection<Ref> haystacks, Enum<E extends Enum<E>> returnStrategy, ProgressMonitor monitor)

public ObjectReader

Returns:

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

Get the reader this walker is using to load objects.

public RevFilter

Returns:

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

Get the currently configured commit filter.

public EnumSet<RevSort>

Returns:

the sorting strategies employed. At least one strategy is always used, but that strategy may be org.eclipse.jgit.revwalk.RevSort#NONE.
getRevSort
()

Obtain the sort types applied to the commits returned.

pack-priv boolean
public TreeFilter

Returns:

the current filter. Never null as a filter is always needed. If no filter is being applied org.eclipse.jgit.treewalk.filter.TreeFilter#ALL is returned.
getTreeFilter
()

Get the tree filter used to simplify commits by modified paths.

public boolean

Returns:

true if this strategy is enabled, false otherwise
hasRevSort
(RevSort
a sorting strategy to look for.
sort
)

Check whether the provided sorting strategy is enabled.

pack-priv void
initializeShallowCommits(RevCommit
the initial commit being parsed
rc
)

Reads the "shallow" file and applies it by setting the parents of shallow commits to an empty array.

public boolean

Returns:

whether only first-parent links should be followed when walking.
isFirstParent
()

Whether only first-parent links should be followed when walking

public boolean

Returns:

true if there is a path directly from tip to base (and thus base is fully merged into tip); false otherwise.
isMergedInto
(RevCommit
commit the caller thinks is reachable from tip.
base
,
RevCommit
commit to start iteration from, and which is most likely a descendant (child) of base.
tip
)

Determine if a commit is reachable from another commit.

public boolean

Returns:

true if commit is merged into all of the refs; false otherwise.
isMergedIntoAll
(RevCommit
commit the caller thinks is reachable from refs.
commit
,
Collection<Ref>
refs to start iteration from, and which is most likely a descendant (child) of commit.
refs
)

Determine if a commit is merged into all of the given refs.

public boolean

Returns:

true if commit is merged into any of the refs; false otherwise.
isMergedIntoAny
(RevCommit
commit the caller thinks is reachable from refs.
commit
,
Collection<Ref>
refs to start iteration from, and which is most likely a descendant (child) of commit.
refs
)

Determine if a commit is merged into any of the given refs.

public boolean

Returns:

true if commit is merged into any of the revs; false otherwise.
isMergedIntoAnyCommit
(RevCommit
commit the caller thinks is reachable from revs.
commit
,
Collection<RevCommit>
commits to start iteration from, and which is most likely a descendant (child) of commit.
revs
)

Determine if a commit is merged into any of the given revs.

private boolean
public boolean

Returns:

true if the body should be retained; false it is discarded.
isRetainBody
()

Should the body of a commit or tag be retained after parsing its headers?

public Iterator<RevCommit>
iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

public RevObject

Returns:

reference to the object. Never null.
lookupAny
(AnyObjectId
name of the object.
id
,
int
type of the object. Must be a valid Git object type.
type
)

Locate a reference to any object without loading it.

public RevBlob

Returns:

reference to the blob object. Never null.
lookupBlob
(AnyObjectId
name of the blob object.
id
)

Locate a reference to a blob without loading it.

public RevCommit

Returns:

reference to the commit object. Never null.
lookupCommit
(AnyObjectId
name of the commit object.
id
)

Locate a reference to a commit without loading it.

protected RevCommit

Returns:

reference to the commit object. Never null.
lookupCommit
(AnyObjectId
name of the commit object.
id
,
int
the position in the commit-graph of the object.
graphPos
)

This method is intended to be invoked only by RevCommitCG, in order to give commit the correct graphPosition before accessing the commit-graph.

public RevObject

Returns:

reference to the object if it has been previously located; otherwise null.
lookupOrNull
(AnyObjectId
name of the object.
id
)

Locate an object that was previously allocated in this walk.

public RevTag

Returns:

reference to the tag object. Never null.
lookupTag
(AnyObjectId
name of the tag object.
id
)

Locate a reference to a tag without loading it.

public RevTree

Returns:

reference to the tree object. Never null.
lookupTree
(AnyObjectId
name of the tree object.
id
)

Locate a reference to a tree without loading it.

public void
markStart(RevCommit
the commit to start traversing from. The commit passed must be from this same revision walker.
c
)

Mark a commit to start graph traversal from.

public void
markStart(Collection<RevCommit>
commits to start traversing from. The commits passed must be from this same revision walker.
list
)

Mark commits to start graph traversal from.

public void
markUninteresting(RevCommit
the commit to start traversing from. The commit passed must be from this same revision walker.
c
)

Mark a commit to not produce in the output.

pack-priv static AbstractRevQueue
newDateRevQueue(boolean firstParent)

pack-priv static DateRevQueue
public RevFlag

Returns:

newly constructed flag instance.
newFlag
(String
description of the flag, primarily useful for debugging.
name
)

Create a new flag for application use during walking.

public RevCommit

Returns:

next most recent commit; null if traversal is over.
next
()

Pop the next most recent commit.

private RevCommit

Returns:

next most recent commit; null if traversal is over.
nextForIterator
()

Like next(), but if a checked exception is thrown during the walk it is rethrown as a RevWalkException.

public RevObject

Returns:

reference to the object. Never null.
parseAny
(AnyObjectId
name of the object.
id
)

Locate a reference to any object and immediately parse its headers.

public <
Type of returned ObjectId
T extends ObjectId
>
AsyncRevObjectQueue

Returns:

queue to read the objects from.
parseAny
(Iterable<T>
objects to open from the object store. The supplied collection must not be modified until the queue has finished.
objectIds
,
boolean
if true missing objects are reported by calling failure with a MissingObjectException. This may be more expensive for the implementation to guarantee. If false the implementation may choose to report MissingObjectException, or silently skip over the object with no warning.
reportMissing
)

Asynchronous object parsing.

public void
parseBody(RevObject
the object the caller needs to be parsed.
obj
)

Ensure the object's full body content is available.

public RevCommit

Returns:

reference to the commit object. Never null.
parseCommit
(AnyObjectId
name of the commit object.
id
)

Locate a reference to a commit and immediately parse its content.

public void
parseHeaders(RevObject
the object the caller needs to be parsed.
obj
)

Ensure the object's critical headers have been parsed.

private RevObject
public RevTag

Returns:

reference to the tag object. Never null.
parseTag
(AnyObjectId
name of the tag object.
id
)

Locate a reference to an annotated tag and immediately parse its content.

public RevTree

Returns:

reference to the tree object. Never null.
parseTree
(AnyObjectId
name of the tree object, or a commit or annotated tag that may reference a tree.
id
)

Locate a reference to a tree.

public RevObject

Returns:

If obj is not an annotated tag, obj. Otherwise the first non-tag object that obj references. The returned object's headers have been parsed.
peel
(RevObject
the starting object.
obj
)

Peel back annotated tags until a non-tag object is found.

public final void
reset()

Resets internal state and allows this instance to be used again.

protected void
reset(int
application flags that should not be cleared from existing commit objects.
retainFlags
)

Resets internal state and allows this instance to be used again.

public final void
resetRetain(RevFlagSet
application flags that should not be cleared from existing commit objects.
retainFlags
)

Resets internal state and allows this instance to be used again.

public final void
resetRetain(RevFlag...
application flags that should not be cleared from existing commit objects.
retainFlags
)

Resets internal state and allows this instance to be used again.

public final void
retainOnReset(RevFlag
the flag to retain during all resets.
flag
)

Preserve a RevFlag during all reset methods.

public final void
retainOnReset(Collection<RevFlag>
the flags to retain during all resets.
flags
)

Preserve a set of RevFlags during all reset methods.

public void
setFirstParent(boolean
true to walk only first-parent links.
enable
)

Set whether or not only first parent links should be followed.

public void
setRetainBody(boolean
true to retain bodies; false to discard them early.
retain
)

Set whether or not the body of a commit or tag is retained.

public void
setRevFilter(RevFilter
the new filter. If null the special org.eclipse.jgit.revwalk.filter.RevFilter#ALL filter will be used instead, as it matches every commit.
newFilter
)

Set the commit filter for this walker.

public void
setRewriteParents(boolean
whether to rewrite parents; defaults to true.
rewrite
)

Set whether to rewrite parent pointers when filtering by modified paths.

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

Set the tree filter used to simplify commits by modified paths.

public void
sort(RevSort
a sorting strategy to enable.
s
)

Select a single sorting strategy for the returned commits.

public void
sort(RevSort
a sorting strategy to enable or disable.
s
,
boolean
true if this strategy should be used, false if it should be removed.
use
)

Add or remove a sorting strategy for the returned commits.

public ObjectWalk

Returns:

a new walk, using the exact same object pool.
toObjectWalkWithSameObjects
()

Create and return an org.eclipse.jgit.revwalk.ObjectWalk using the same objects.

private static boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait