private int delayFreeFlags;
+ private int retainOnReset;
int carryFlags = UNINTERESTING;
final ArrayList<RevCommit> roots;
carry(flag);
}
+ /**
+ * Preserve a RevFlag during all {@code reset} methods.
+ * <p>
+ * Calling {@code retainOnReset(flag)} avoids needing to pass the flag
+ * during each {@code resetRetain()} invocation on this instance.
+ * <p>
+ * Clearing flags marked retainOnReset requires disposing of the flag with
+ * {@code #disposeFlag(RevFlag)} or disposing of the entire RevWalk by
+ * {@code #dispose()}.
+ *
+ * @param flag
+ * the flag to retain during all resets.
+ * @since 3.6
+ */
+ public final void retainOnReset(RevFlag flag) {
+ if ((freeFlags & flag.mask) != 0)
+ throw new IllegalArgumentException(MessageFormat.format(JGitText.get().flagIsDisposed, flag.name));
+ if (flag.walker != this)
+ throw new IllegalArgumentException(MessageFormat.format(JGitText.get().flagNotFromThis, flag.name));
+ retainOnReset |= flag.mask;
+ }
+
+ /**
+ * Preserve a set of RevFlags during all {@code reset} methods.
+ * <p>
+ * Calling {@code retainOnReset(set)} avoids needing to pass the flags
+ * during each {@code resetRetain()} invocation on this instance.
+ * <p>
+ * Clearing flags marked retainOnReset requires disposing of the flag with
+ * {@code #disposeFlag(RevFlag)} or disposing of the entire RevWalk by
+ * {@code #dispose()}.
+ *
+ * @param flags
+ * the flags to retain during all resets.
+ * @since 3.6
+ */
+ public final void retainOnReset(Collection<RevFlag> flags) {
+ for (RevFlag f : flags)
+ retainOnReset(f);
+ }
+
/**
* Allow a flag to be recycled for a different use.
* <p>
}
void freeFlag(final int mask) {
+ retainOnReset &= ~mask;
if (isNotStarted()) {
freeFlags |= mask;
carryFlags &= ~mask;
* Unlike {@link #dispose()} previously acquired RevObject (and RevCommit)
* instances are not invalidated. RevFlag instances are not invalidated, but
* are removed from all RevObjects.
+ * <p>
+ * See {@link #retainOnReset(RevFlag)} for an alternative that does not
+ * require passing the flags during each reset.
*
* @param retainFlags
* application flags that should <b>not</b> be cleared from
*/
protected void reset(int retainFlags) {
finishDelayedFreeFlags();
- retainFlags |= PARSED;
+ retainFlags |= PARSED | retainOnReset;
final int clearFlags = ~retainFlags;
final FIFORevQueue q = new FIFORevQueue();
reader.release();
freeFlags = APP_FLAGS;
delayFreeFlags = 0;
+ retainOnReset = 0;
carryFlags = UNINTERESTING;
objects.clear();
reader.release();