import java.util.List;
import org.eclipse.jgit.annotations.NonNull;
+import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.LargeObjectException;
shallowCommitsInitialized = false;
}
+ /**
+ * Like {@link #next()}, but if a checked exception is thrown during the
+ * walk it is rethrown as a {@link RevWalkException}.
+ *
+ * @throws RevWalkException if an {@link IOException} was thrown.
+ * @return next most recent commit; null if traversal is over.
+ */
+ @Nullable
+ private RevCommit nextForIterator() {
+ try {
+ return next();
+ } catch (IOException e) {
+ throw new RevWalkException(e);
+ }
+ }
+
/**
* {@inheritDoc}
* <p>
*/
@Override
public Iterator<RevCommit> iterator() {
- final RevCommit first;
- try {
- first = RevWalk.this.next();
- } catch (IOException e) {
- throw new RevWalkException(e);
- }
+ RevCommit first = nextForIterator();
return new Iterator<RevCommit>() {
RevCommit next = first;
@Override
public RevCommit next() {
- try {
- final RevCommit r = next;
- next = RevWalk.this.next();
- return r;
- } catch (IOException e) {
- throw new RevWalkException(e);
- }
+ RevCommit r = next;
+ next = nextForIterator();
+ return r;
}
@Override