Class RevWalk
- All Implemented Interfaces:
AutoCloseable
,Iterable<RevCommit>
- Direct Known Subclasses:
DepthWalk.RevWalk
,ObjectWalk
,PlotWalk
,ReverseWalk
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
Repository
are permitted, even from concurrent
threads. Equality of RevCommit
s from two
different RevWalk instances is never true, even if their
ObjectId
s 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 Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
(package private) int
private final boolean
private int
private RevFilter
private boolean
(package private) int
(package private) final MutableObjectId
private static final int
(package private) ObjectIdOwnerMap<RevObject>
(package private) static final int
Set on objects whose important header data has been loaded.(package private) Generator
(package private) AbstractRevQueue
(package private) final ObjectReader
(package private) static final int
Number of flag bits we keep internal for our own use.private boolean
private int
(package private) static final int
Set on a RevCommit that can collapse out of the history.private boolean
(package private) static final int
Set on RevCommit instances added to ourpending
queue.(package private) boolean
(package private) static final int
Temporary mark for use within generators or filters.(package private) static final int
Temporary mark for use withinTopoSortGenerator
.(package private) static final int
Temporary mark for use withinTopoNonIntermixSortGenerator
.private TreeFilter
(package private) static final int
Set on RevCommit instances the caller does not want output. -
Constructor Summary
ConstructorsConstructorDescriptionRevWalk
(ObjectReader or) Create a new revision walker for a given repository.RevWalk
(ObjectReader or, boolean closeReader) RevWalk
(Repository repo) Create a new revision walker for a given repository. -
Method Summary
Modifier and TypeMethodDescription(package private) int
protected void
Throws an exception if any commits have been marked as start.protected void
Throws an exception if we have started producing output.void
assumeShallow
(Collection<? extends ObjectId> ids) Assume additional commits are shallow (have no parents).void
carry
(Collection<RevFlag> set) Automatically carry flags from a child commit to its parents.void
Automatically carry a flag from a child commit to its parents.(package private) void
void
close()
protected RevCommit
Construct a new unparsed commit for the given object.final ReachabilityChecker
Deprecated.void
dispose()
Dispose all internal state and invalidate all RevObject instances.void
disposeFlag
(RevFlag flag) Allow a flag to be recycled for a different use.private void
(package private) void
freeFlag
(int mask) (package private) byte[]
getCachedBytes
(RevObject obj) (package private) byte[]
getCachedBytes
(RevObject obj, ObjectLoader ldr) getMergedInto
(RevCommit commit, Collection<Ref> refs) Determine the Refs into which a commit is merged.getMergedInto
(RevCommit needle, Collection<Ref> haystacks, Enum returnStrategy, ProgressMonitor monitor) getMergedInto
(RevCommit commit, Collection<Ref> refs, ProgressMonitor monitor) Determine the Refs into which a commit is merged.Get the reader this walker is using to load objects.Get the currently configured commit filter.Obtain the sort types applied to the commits returned.(package private) boolean
Get the tree filter used to simplify commits by modified paths.boolean
hasRevSort
(RevSort sort) Check whether the provided sorting strategy is enabled.(package private) void
Reads the "shallow" file and applies it by setting the parents of shallow commits to an empty array.boolean
boolean
isMergedInto
(RevCommit base, RevCommit tip) Determine if a commit is reachable from another commit.boolean
isMergedIntoAll
(RevCommit commit, Collection<Ref> refs) Determine if acommit
is merged into all of the givenrefs
.boolean
isMergedIntoAny
(RevCommit commit, Collection<Ref> refs) Determine if acommit
is merged into any of the givenrefs
.private boolean
boolean
Should the body of a commit or tag be retained after parsing its headers?iterator()
lookupAny
(AnyObjectId id, int type) Locate a reference to any object without loading it.Locate a reference to a blob without loading it.Locate a reference to a commit without loading it.Locate an object that was previously allocated in this walk.lookupTag
(AnyObjectId id) Locate a reference to a tag without loading it.Locate a reference to a tree without loading it.void
markStart
(Collection<RevCommit> list) Mark commits to start graph traversal from.void
Mark a commit to start graph traversal from.void
Mark a commit to not produce in the output.Create a new flag for application use during walking.next()
Pop the next most recent commit.private RevCommit
Likenext()
, but if a checked exception is thrown during the walk it is rethrown as aRevWalkException
.<T extends ObjectId>
AsyncRevObjectQueueAsynchronous object parsing.parseAny
(AnyObjectId id) Locate a reference to any object and immediately parse its headers.void
Ensure the object's full body content is available.Locate a reference to a commit and immediately parse its content.void
parseHeaders
(RevObject obj) Ensure the object's critical headers have been parsed.private RevObject
parseNew
(AnyObjectId id, ObjectLoader ldr) parseTag
(AnyObjectId id) Locate a reference to an annotated tag and immediately parse its content.parseTree
(AnyObjectId id) Locate a reference to a tree.Peel back annotated tags until a non-tag object is found.final void
reset()
Resets internal state and allows this instance to be used again.protected void
reset
(int retainFlags) Resets internal state and allows this instance to be used again.final void
resetRetain
(RevFlag... retainFlags) Resets internal state and allows this instance to be used again.final void
resetRetain
(RevFlagSet retainFlags) Resets internal state and allows this instance to be used again.final void
retainOnReset
(Collection<RevFlag> flags) Preserve a set of RevFlags during allreset
methods.final void
retainOnReset
(RevFlag flag) Preserve a RevFlag during allreset
methods.void
setFirstParent
(boolean enable) Set whether or not only first parent links should be followed.void
setRetainBody
(boolean retain) Set whether or not the body of a commit or tag is retained.void
setRevFilter
(RevFilter newFilter) Set the commit filter for this walker.void
setRewriteParents
(boolean rewrite) Set whether to rewrite parent pointers when filtering by modified paths.void
setTreeFilter
(TreeFilter newFilter) Set the tree filter used to simplify commits by modified paths.void
Select a single sorting strategy for the returned commits.void
Add or remove a sorting strategy for the returned commits.Create and return anObjectWalk
using the same objects.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
-
MB
private static final int MB- See Also:
-
PARSED
static final int PARSEDSet on objects whose important header data has been loaded.For a RevCommit this indicates we have pulled apart the tree and parent references from the raw bytes available in the repository and translated those to our own local RevTree and RevCommit instances. The raw buffer is also available for message and other header filtering.
For a RevTag this indicates we have pulled part the tag references to find out who the tag refers to, and what that object's type is.
- See Also:
-
SEEN
static final int SEENSet on RevCommit instances added to ourpending
queue.We use this flag to avoid adding the same commit instance twice to our queue, especially if we reached it by more than one path.
- See Also:
-
UNINTERESTING
static final int UNINTERESTINGSet on RevCommit instances the caller does not want output.We flag commits as uninteresting if the caller does not want commits reachable from a commit given to
markUninteresting(RevCommit)
. This flag is always carried into the commit's parents and is a key part of the "rev-list B --not A" feature; A is marked UNINTERESTING.- See Also:
-
REWRITE
static final int REWRITESet on a RevCommit that can collapse out of the history.If the
treeFilter
concluded that this commit matches his parents' for all of the paths that the filter is interested in then we mark the commit REWRITE. Later we can rewrite the parents of a REWRITE child to remove chains of REWRITE commits before we produce the child to the application.- See Also:
-
TEMP_MARK
static final int TEMP_MARKTemporary mark for use within generators or filters.This mark is only for local use within a single scope. If someone sets the mark they must unset it before any other code can see the mark.
- See Also:
-
TOPO_DELAY
static final int TOPO_DELAYTemporary mark for use withinTopoSortGenerator
.This mark indicates the commit could not produce when it wanted to, as at least one child was behind it. Commits with this flag are delayed until all children have been output first.
- See Also:
-
TOPO_QUEUED
static final int TOPO_QUEUEDTemporary mark for use withinTopoNonIntermixSortGenerator
.This mark indicates the commit has been queued for emission in
TopoSortGenerator
and can be produced. This mark is removed when the commit has been produced.- See Also:
-
RESERVED_FLAGS
static final int RESERVED_FLAGSNumber of flag bits we keep internal for our own use. See above flags.- See Also:
-
APP_FLAGS
private static final int APP_FLAGS- See Also:
-
reader
-
closeReader
private final boolean closeReader -
idBuffer
-
objects
ObjectIdOwnerMap<RevObject> objects -
freeFlags
int freeFlags -
delayFreeFlags
private int delayFreeFlags -
retainOnReset
private int retainOnReset -
carryFlags
int carryFlags -
roots
-
queue
AbstractRevQueue queue -
pending
Generator pending -
sorting
-
filter
-
treeFilter
-
retainBody
private boolean retainBody -
rewriteParents
private boolean rewriteParents -
firstParent
private boolean firstParent -
shallowCommitsInitialized
boolean shallowCommitsInitialized
-
-
Constructor Details
-
RevWalk
Create a new revision walker for a given repository.- Parameters:
repo
- 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.
-
RevWalk
Create a new revision walker for a given repository.- Parameters:
or
- the reader the walker will obtain data from. The reader is not closed when the walker is closed (but is closed bydispose()
.
-
RevWalk
RevWalk(ObjectReader or, boolean closeReader)
-
-
Method Details
-
getObjectReader
Get the reader this walker is using to load objects.- Returns:
- the reader this walker is using to load objects.
-
createReachabilityChecker
Deprecated.useObjectReader#createReachabilityChecker(RevWalk)
instead.Get a reachability checker for commits over this revwalk.- Returns:
- the most efficient reachability checker for this repository.
- Throws:
IOException
- if it cannot open any of the underlying indices.- Since:
- 5.4
-
close
public void close()Release any resources used by this walker's reader.
A walker that has been released can be used again, but may need to be released after the subsequent usage.
- Specified by:
close
in interfaceAutoCloseable
- Since:
- 4.0
-
markStart
public void markStart(RevCommit c) throws MissingObjectException, IncorrectObjectTypeException, IOException Mark a commit to start graph traversal from.Callers are encouraged to use
parseCommit(AnyObjectId)
to obtain the commit reference, rather thanlookupCommit(AnyObjectId)
, as this method requires the commit to be parsed before it can be added as a root for the traversal.The method will automatically parse an unparsed commit, but error handling may be more difficult for the application to explain why a RevCommit is not actually a commit. The object pool of this walker would also be 'poisoned' by the non-commit RevCommit.
- Parameters:
c
- the commit to start traversing from. The commit passed must be from this same revision walker.- Throws:
MissingObjectException
- the commit supplied is not available from the object database. This usually indicates the supplied commit is invalid, but the reference was constructed during an earlier invocation tolookupCommit(AnyObjectId)
.IncorrectObjectTypeException
- the object was not parsed yet and it was discovered during parsing that it is not actually a commit. This usually indicates the caller supplied a non-commit SHA-1 tolookupCommit(AnyObjectId)
.IOException
- a pack file or loose object could not be read.
-
markStart
public void markStart(Collection<RevCommit> list) throws MissingObjectException, IncorrectObjectTypeException, IOException Mark commits to start graph traversal from.- Parameters:
list
- commits to start traversing from. The commits passed must be from this same revision walker.- Throws:
MissingObjectException
- one of the commits supplied is not available from the object database. This usually indicates the supplied commit is invalid, but the reference was constructed during an earlier invocation tolookupCommit(AnyObjectId)
.IncorrectObjectTypeException
- the object was not parsed yet and it was discovered during parsing that it is not actually a commit. This usually indicates the caller supplied a non-commit SHA-1 tolookupCommit(AnyObjectId)
.IOException
- a pack file or loose object could not be read.
-
markUninteresting
public void markUninteresting(RevCommit c) throws MissingObjectException, IncorrectObjectTypeException, IOException Mark a commit to not produce in the output.Uninteresting commits denote not just themselves but also their entire ancestry chain, back until the merge base of an uninteresting commit and an otherwise interesting commit.
Callers are encouraged to use
parseCommit(AnyObjectId)
to obtain the commit reference, rather thanlookupCommit(AnyObjectId)
, as this method requires the commit to be parsed before it can be added as a root for the traversal.The method will automatically parse an unparsed commit, but error handling may be more difficult for the application to explain why a RevCommit is not actually a commit. The object pool of this walker would also be 'poisoned' by the non-commit RevCommit.
- Parameters:
c
- the commit to start traversing from. The commit passed must be from this same revision walker.- Throws:
MissingObjectException
- the commit supplied is not available from the object database. This usually indicates the supplied commit is invalid, but the reference was constructed during an earlier invocation tolookupCommit(AnyObjectId)
.IncorrectObjectTypeException
- the object was not parsed yet and it was discovered during parsing that it is not actually a commit. This usually indicates the caller supplied a non-commit SHA-1 tolookupCommit(AnyObjectId)
.IOException
- a pack file or loose object could not be read.
-
isMergedInto
public boolean isMergedInto(RevCommit base, RevCommit tip) throws MissingObjectException, IncorrectObjectTypeException, IOException Determine if a commit is reachable from another commit.A commit
base
is an ancestor oftip
if we can find a path of commits that leads fromtip
and ends atbase
.This utility function resets the walker, inserts the two supplied commits, and then executes a walk until an answer can be obtained. Currently allocated RevFlags that have been added to RevCommit instances will be retained through the reset.
- Parameters:
base
- commit the caller thinks is reachable fromtip
.tip
- commit to start iteration from, and which is most likely a descendant (child) ofbase
.- Returns:
- true if there is a path directly from
tip
tobase
(and thusbase
is fully merged intotip
); false otherwise. - 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.
-
getMergedInto
Determine the Refs into which a commit is merged.A commit is merged into a ref if we can find a path of commits that leads from that specific ref and ends at
commit
.- Parameters:
commit
- commit the caller thinks is reachable fromrefs
.refs
- refs to start iteration from, and which is most likely a descendant (child) ofcommit
.- Returns:
- list of refs that are reachable from
commit
. - Throws:
IOException
- a pack file or loose object could not be read.- Since:
- 5.12
-
getMergedInto
public List<Ref> getMergedInto(RevCommit commit, Collection<Ref> refs, ProgressMonitor monitor) throws IOException Determine the Refs into which a commit is merged.A commit is merged into a ref if we can find a path of commits that leads from that specific ref and ends at
commit
.- Parameters:
commit
- commit the caller thinks is reachable fromrefs
.refs
- refs to start iteration from, and which is most likely a descendant (child) ofcommit
.monitor
- the callback for progress and cancellation- Returns:
- list of refs that are reachable from
commit
. - Throws:
IOException
- a pack file or loose object could not be read.- Since:
- 5.12
-
isMergedIntoAny
Determine if acommit
is merged into any of the givenrefs
.- Parameters:
commit
- commit the caller thinks is reachable fromrefs
.refs
- refs to start iteration from, and which is most likely a descendant (child) ofcommit
.- Returns:
- true if commit is merged into any of the refs; false otherwise.
- Throws:
IOException
- a pack file or loose object could not be read.- Since:
- 5.12
-
isMergedIntoAll
Determine if acommit
is merged into all of the givenrefs
.- Parameters:
commit
- commit the caller thinks is reachable fromrefs
.refs
- refs to start iteration from, and which is most likely a descendant (child) ofcommit
.- Returns:
- true if commit is merged into all of the refs; false otherwise.
- Throws:
IOException
- a pack file or loose object could not be read.- Since:
- 5.12
-
getMergedInto
private List<Ref> getMergedInto(RevCommit needle, Collection<Ref> haystacks, Enum returnStrategy, ProgressMonitor monitor) throws IOException - Throws:
IOException
-
next
Pop the next most recent commit.- 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.
-
getRevSort
Obtain the sort types applied to the commits returned.- Returns:
- the sorting strategies employed. At least one strategy is always
used, but that strategy may be
RevSort.NONE
.
-
hasRevSort
Check whether the provided sorting strategy is enabled.- Parameters:
sort
- a sorting strategy to look for.- Returns:
- true if this strategy is enabled, false otherwise
-
sort
Select a single sorting strategy for the returned commits.Disables all sorting strategies, then enables only the single strategy supplied by the caller.
- Parameters:
s
- a sorting strategy to enable.
-
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.- Parameters:
s
- a sorting strategy to enable or disable.use
- true if this strategy should be used, false if it should be removed.
-
getRevFilter
Get the currently configured commit filter.- Returns:
- the current filter. Never null as a filter is always needed.
-
setRevFilter
Set the commit filter for this walker.Multiple filters may be combined by constructing an arbitrary tree of
AndRevFilter
orOrRevFilter
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 RevWalk instances. Every RevWalk must be supplied its own unique filter, unless the filter implementation specifically states it is (and always will be) thread-safe. Callers may use
RevFilter.clone()
to create a unique filter tree for this RevWalk instance.- Parameters:
newFilter
- the new filter. If null the specialRevFilter.ALL
filter will be used instead, as it matches every commit.- See Also:
-
getTreeFilter
Get the tree filter used to simplify commits by modified paths.- Returns:
- the current filter. Never null as a filter is always needed. If
no filter is being applied
TreeFilter.ALL
is returned.
-
setTreeFilter
Set the tree filter used to simplify commits by modified paths.If null or
TreeFilter.ALL
the path limiter is removed. Commits will not be simplified.If non-null and not
TreeFilter.ALL
then the tree filter will be installed. Commits will have their ancestry simplified to hide commits that do not contain tree entries matched by the filter, unlesssetRewriteParents(false)
is called.Usually callers should be inserting a filter graph including
TreeFilter.ANY_DIFF
along with one or morePathFilter
instances.- Parameters:
newFilter
- new filter. If null the specialTreeFilter.ALL
filter will be used instead, as it matches everything.- See Also:
-
setRewriteParents
public void setRewriteParents(boolean rewrite) Set whether to rewrite parent pointers when filtering by modified paths.By default, when
setTreeFilter(TreeFilter)
is called with non- null and non-TreeFilter.ALL
filter, commits will have their ancestry simplified and parents rewritten to hide commits that do not match the filter.This behavior can be bypassed by passing false to this method.
- Parameters:
rewrite
- whether to rewrite parents; defaults to true.- Since:
- 3.4
-
getRewriteParents
boolean getRewriteParents() -
isRetainBody
public boolean isRetainBody()Should the body of a commit or tag be retained after parsing its headers?Usually the body is always retained, but some application code might not care and would prefer to discard the body of a commit as early as possible, to reduce memory usage.
True by default on
RevWalk
and false by default forObjectWalk
.- Returns:
- true if the body should be retained; false it is discarded.
-
setRetainBody
public void setRetainBody(boolean retain) Set whether or not the body of a commit or tag is retained.If a body of a commit or tag is not retained, the application must call
parseBody(RevObject)
before the body can be safely accessed through the type specific access methods.True by default on
RevWalk
and false by default forObjectWalk
.- Parameters:
retain
- true to retain bodies; false to discard them early.
-
isFirstParent
public boolean isFirstParent()- Returns:
- whether only first-parent links should be followed when walking.
- Since:
- 5.5
-
setFirstParent
public void setFirstParent(boolean enable) Set whether or not only first parent links should be followed.If set, second- and higher-parent links are not traversed at all.
This must be called prior to
markStart(RevCommit)
.- Parameters:
enable
- true to walk only first-parent links.- Since:
- 5.5
-
lookupBlob
Locate a reference to a blob without loading it.The blob may or may not exist in the repository. It is impossible to tell from this method's return value.
- Parameters:
id
- name of the blob object.- Returns:
- reference to the blob object. Never null.
-
lookupTree
Locate a reference to a tree without loading it.The tree may or may not exist in the repository. It is impossible to tell from this method's return value.
- Parameters:
id
- name of the tree object.- Returns:
- reference to the tree object. Never null.
-
lookupCommit
Locate a reference to a commit without loading it.The commit may or may not exist in the repository. It is impossible to tell from this method's return value.
See
parseHeaders(RevObject)
andparseBody(RevObject)
for loading contents.- Parameters:
id
- name of the commit object.- Returns:
- reference to the commit object. Never null.
-
lookupTag
Locate a reference to a tag without loading it.The tag may or may not exist in the repository. It is impossible to tell from this method's return value.
- Parameters:
id
- name of the tag object.- Returns:
- reference to the tag object. Never null.
-
lookupAny
Locate a reference to any object without loading it.The object may or may not exist in the repository. It is impossible to tell from this method's return value.
- Parameters:
id
- name of the object.type
- type of the object. Must be a valid Git object type.- Returns:
- reference to the object. Never null.
-
lookupOrNull
Locate an object that was previously allocated in this walk.- Parameters:
id
- name of the object.- Returns:
- reference to the object if it has been previously located; otherwise null.
-
parseCommit
@NonNull public RevCommit parseCommit(AnyObjectId id) throws MissingObjectException, IncorrectObjectTypeException, IOException Locate a reference to a commit and immediately parse its content.Unlike
lookupCommit(AnyObjectId)
this method only returns successfully if the commit object exists, is verified to be a commit, and was parsed without error.- Parameters:
id
- name of the commit object.- Returns:
- reference to the commit object. Never null.
- Throws:
MissingObjectException
- the supplied commit does not exist.IncorrectObjectTypeException
- the supplied id is not a commit or an annotated tag.IOException
- a pack file or loose object could not be read.
-
parseTree
@NonNull public RevTree parseTree(AnyObjectId id) throws MissingObjectException, IncorrectObjectTypeException, IOException Locate a reference to a tree.This method only returns successfully if the tree object exists, is verified to be a tree.
- Parameters:
id
- name of the tree object, or a commit or annotated tag that may reference a tree.- Returns:
- reference to the tree object. Never null.
- Throws:
MissingObjectException
- the supplied tree does not exist.IncorrectObjectTypeException
- the supplied id is not a tree, a commit or an annotated tag.IOException
- a pack file or loose object could not be read.
-
parseTag
@NonNull public RevTag parseTag(AnyObjectId id) throws MissingObjectException, IncorrectObjectTypeException, IOException Locate a reference to an annotated tag and immediately parse its content.Unlike
lookupTag(AnyObjectId)
this method only returns successfully if the tag object exists, is verified to be a tag, and was parsed without error.- Parameters:
id
- name of the tag object.- Returns:
- reference to the tag object. Never null.
- Throws:
MissingObjectException
- the supplied tag does not exist.IncorrectObjectTypeException
- the supplied id is not a tag or an annotated tag.IOException
- a pack file or loose object could not be read.
-
parseAny
Locate a reference to any object and immediately parse its headers.This method only returns successfully if the object exists and was parsed without error. Parsing an object can be expensive as the type must be determined. For blobs this may mean the blob content was unpacked unnecessarily, and thrown away.
- Parameters:
id
- name of the object.- Returns:
- reference to the object. Never null.
- Throws:
MissingObjectException
- the supplied does not exist.IOException
- a pack file or loose object could not be read.
-
parseNew
private RevObject parseNew(AnyObjectId id, ObjectLoader ldr) throws LargeObjectException, CorruptObjectException, MissingObjectException, IOException -
getCachedBytes
byte[] getCachedBytes(RevObject obj) throws LargeObjectException, MissingObjectException, IncorrectObjectTypeException, IOException -
getCachedBytes
byte[] getCachedBytes(RevObject obj, ObjectLoader ldr) throws LargeObjectException, MissingObjectException, IOException -
parseAny
public <T extends ObjectId> AsyncRevObjectQueue parseAny(Iterable<T> objectIds, boolean reportMissing) Asynchronous object parsing.- Parameters:
objectIds
- objects to open from the object store. The supplied collection must not be modified until the queue has finished.reportMissing
- 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.- Returns:
- queue to read the objects from.
-
parseHeaders
Ensure the object's critical headers have been parsed.This method only returns successfully if the object exists and was parsed without error.
- Parameters:
obj
- the object the caller needs to be parsed.- Throws:
MissingObjectException
- the supplied does not exist.IOException
- a pack file or loose object could not be read.
-
parseBody
Ensure the object's full body content is available.This method only returns successfully if the object exists and was parsed without error.
- Parameters:
obj
- the object the caller needs to be parsed.- Throws:
MissingObjectException
- the supplied does not exist.IOException
- a pack file or loose object could not be read.
-
peel
Peel back annotated tags until a non-tag object is found.- Parameters:
obj
- the starting object.- Returns:
- If
obj
is not an annotated tag,obj
. Otherwise the first non-tag object thatobj
references. The returned object's headers have been parsed. - Throws:
MissingObjectException
- a referenced object cannot be found.IOException
- a pack file or loose object could not be read.
-
newFlag
Create a new flag for application use during walking.Applications are only assured to be able to create 24 unique flags on any given revision walker instance. Any flags beyond 24 are offered only if the implementation has extra free space within its internal storage.
- Parameters:
name
- description of the flag, primarily useful for debugging.- Returns:
- newly constructed flag instance.
- Throws:
IllegalArgumentException
- too many flags have been reserved on this revision walker.
-
allocFlag
int allocFlag() -
carry
Automatically carry a flag from a child commit to its parents.A carried flag is copied from the child commit onto its parents when the child commit is popped from the lowest level of walk's internal graph.
- Parameters:
flag
- the flag to carry onto parents, if set on a descendant.
-
carry
Automatically carry flags from a child commit to its parents.A carried flag is copied from the child commit onto its parents when the child commit is popped from the lowest level of walk's internal graph.
- Parameters:
set
- the flags to carry onto parents, if set on a descendant.
-
retainOnReset
Preserve a RevFlag during allreset
methods.Calling
retainOnReset(flag)
avoids needing to pass the flag during eachresetRetain()
invocation on this instance.Clearing flags marked retainOnReset requires disposing of the flag with
#disposeFlag(RevFlag)
or disposing of the entire RevWalk by#dispose()
.- Parameters:
flag
- the flag to retain during all resets.- Since:
- 3.6
-
retainOnReset
Preserve a set of RevFlags during allreset
methods.Calling
retainOnReset(set)
avoids needing to pass the flags during eachresetRetain()
invocation on this instance.Clearing flags marked retainOnReset requires disposing of the flag with
#disposeFlag(RevFlag)
or disposing of the entire RevWalk by#dispose()
.- Parameters:
flags
- the flags to retain during all resets.- Since:
- 3.6
-
disposeFlag
Allow a flag to be recycled for a different use.Recycled flags always come back as a different Java object instance when assigned again by
newFlag(String)
.If the flag was previously being carried, the carrying request is removed. Disposing of a carried flag while a traversal is in progress has an undefined behavior.
- Parameters:
flag
- the to recycle.
-
freeFlag
void freeFlag(int mask) -
finishDelayedFreeFlags
private void finishDelayedFreeFlags() -
reset
public final void reset()Resets internal state and allows this instance to be used again.Unlike
dispose()
previously acquired RevObject (and RevCommit) instances are not invalidated. RevFlag instances are not invalidated, but are removed from all RevObjects. -
resetRetain
Resets internal state and allows this instance to be used again.Unlike
dispose()
previously acquired RevObject (and RevCommit) instances are not invalidated. RevFlag instances are not invalidated, but are removed from all RevObjects.- Parameters:
retainFlags
- application flags that should not be cleared from existing commit objects.
-
resetRetain
Resets internal state and allows this instance to be used again.Unlike
dispose()
previously acquired RevObject (and RevCommit) instances are not invalidated. RevFlag instances are not invalidated, but are removed from all RevObjects.See
retainOnReset(RevFlag)
for an alternative that does not require passing the flags during each reset.- Parameters:
retainFlags
- application flags that should not be cleared from existing commit objects.
-
reset
protected void reset(int retainFlags) Resets internal state and allows this instance to be used again.Unlike
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.- Parameters:
retainFlags
- application flags that should not be cleared from existing commit objects.
-
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.
-
nextForIterator
Likenext()
, but if a checked exception is thrown during the walk it is rethrown as aRevWalkException
.- Returns:
- next most recent commit; null if traversal is over.
- Throws:
RevWalkException
- if anIOException
was thrown.
-
iterator
Returns an Iterator over the commits of this walker.
The returned iterator is only useful for one walk. If this RevWalk gets reset a new iterator must be obtained to walk over the new results.
Applications must not use both the Iterator and the
next()
API at the same time. Pick one API and use that for the entire walk.If a checked exception is thrown during the walk (see
next()
) it is rethrown from the Iterator as aRevWalkException
. -
assertNotStarted
protected void assertNotStarted()Throws an exception if we have started producing output. -
assertNoCommitsMarkedStart
protected void assertNoCommitsMarkedStart()Throws an exception if any commits have been marked as start.If
markStart(RevCommit)
has already been called,reset()
can be called to satisfy this condition.- Since:
- 5.5
-
isNotStarted
private boolean isNotStarted() -
toObjectWalkWithSameObjects
Create and return anObjectWalk
using the same objects.Prior to using this method, the caller must reset this RevWalk to clean any flags that were used during the last traversal.
The returned ObjectWalk uses the same ObjectReader, internal object pool, and free RevFlags. Once the ObjectWalk is created, this RevWalk should not be used anymore.
- Returns:
- a new walk, using the exact same object pool.
-
createCommit
Construct a new unparsed commit for the given object.- Parameters:
id
- the object this walker requires a commit reference for.- Returns:
- a new unparsed reference for the object.
-
carryFlagsImpl
-
assumeShallow
Assume additional commits are shallow (have no parents).This method is a No-op if the collection is empty.
- Parameters:
ids
- commits that should be treated as shallow commits, in addition to any commits already known to be shallow by the repository.- Since:
- 3.3
-
initializeShallowCommits
Reads the "shallow" file and applies it by setting the parents of shallow commits to an empty array.There is a sequencing problem if the first commit being parsed is a shallow commit, since
RevCommit.parseCanonical(RevWalk, byte[])
calls this method before its callers add the new commit to theobjects
map. That means a call from this method tolookupCommit(AnyObjectId)
fails to find that commit and creates a new one, which is promptly discarded.To avoid that,
RevCommit.parseCanonical(RevWalk, byte[])
passes its commit to this method, so that this method can apply the shallow state to it directly and avoid creating the duplicate commit object.- Parameters:
rc
- the initial commit being parsed- Throws:
IOException
- if the shallow commits file can't be read
-
ObjectReader#createReachabilityChecker(RevWalk)
instead.