aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2018-11-08 22:51:48 -0500
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2018-11-08 22:51:48 -0500
commit54dd1d112a46a2b5a76fcdc1776c21fb110e497f (patch)
treebd5d97af580ec6c47469ca754f9378c454c4bdce /org.eclipse.jgit
parentdf21eec1adb87a9000a62562f46ef3ff76cad482 (diff)
parenta0cd400c37bb861264fa2147f94123c6f0e19b7c (diff)
downloadjgit-54dd1d112a46a2b5a76fcdc1776c21fb110e497f.tar.gz
jgit-54dd1d112a46a2b5a76fcdc1776c21fb110e497f.zip
Merge changes I97c062d0,Ib4e1f37c
* changes: Simplify RevWalk#iterator by factoring out common code Simplify exception handling in RevWalk#iterator
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java42
1 files changed, 21 insertions, 21 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java
index 4d555d2178..400ea33c21 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java
@@ -54,6 +54,7 @@ import java.util.Iterator;
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;
@@ -1336,6 +1337,22 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable {
}
/**
+ * 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>
* Returns an Iterator over the commits of this walker.
@@ -1353,16 +1370,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable {
*/
@Override
public Iterator<RevCommit> iterator() {
- final RevCommit first;
- try {
- first = RevWalk.this.next();
- } catch (MissingObjectException e) {
- throw new RevWalkException(e);
- } catch (IncorrectObjectTypeException e) {
- throw new RevWalkException(e);
- } catch (IOException e) {
- throw new RevWalkException(e);
- }
+ RevCommit first = nextForIterator();
return new Iterator<RevCommit>() {
RevCommit next = first;
@@ -1374,17 +1382,9 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable {
@Override
public RevCommit next() {
- try {
- final RevCommit r = next;
- next = RevWalk.this.next();
- return r;
- } catch (MissingObjectException e) {
- throw new RevWalkException(e);
- } catch (IncorrectObjectTypeException e) {
- throw new RevWalkException(e);
- } catch (IOException e) {
- throw new RevWalkException(e);
- }
+ RevCommit r = next;
+ next = nextForIterator();
+ return r;
}
@Override