]> source.dussan.org Git - jgit.git/commitdiff
ObjectReader: Allow getCommitGraph to throw IOException 85/199785/4
authorXing Huang <xingkhuang@google.com>
Mon, 6 Feb 2023 20:18:16 +0000 (14:18 -0600)
committerIvan Frade <ifrade@google.com>
Tue, 7 Feb 2023 16:32:12 +0000 (11:32 -0500)
ObjectReader#getCommitGraph doesn't report errors loading the
commit graph. The caller should be aware of the situation and
ultimately decide what to do.

Add IOException to ObjectReader#getCommitGraph signature. RevWalk
defaults to an empty commit-graph on IO errors.

Signed-off-by: Xing Huang <xingkhuang@google.com>
Change-Id: I38eeacff76c7f926b6dfb192d1e5916e40770024

org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java

index ae0cf42b12d764092743d9cb013f0460ae6cf104..69b2b5104e4be4a0152c8277991c65608195b08d 100644 (file)
@@ -512,9 +512,12 @@ public abstract class ObjectReader implements AutoCloseable {
         *         (default is
         *         {@value org.eclipse.jgit.lib.CoreConfig#DEFAULT_COMMIT_GRAPH_ENABLE}).
         *
+        * @throws IOException
+        *             if it cannot open any of the underlying commit graph.
+        *
         * @since 6.5
         */
-       public Optional<CommitGraph> getCommitGraph() {
+       public Optional<CommitGraph> getCommitGraph() throws IOException {
                return Optional.empty();
        }
 
@@ -661,7 +664,7 @@ public abstract class ObjectReader implements AutoCloseable {
                }
 
                @Override
-               public Optional<CommitGraph> getCommitGraph() {
+               public Optional<CommitGraph> getCommitGraph() throws IOException{
                        return delegate().getCommitGraph();
                }
 
index a66e7c86bd736204a18fa0f826e9c1881f296919..9da7105566cf588d37e731acc5d7d26d6676cd8d 100644 (file)
@@ -1173,8 +1173,13 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable {
        @NonNull
        CommitGraph commitGraph() {
                if (commitGraph == null) {
-                       commitGraph = reader != null ? reader.getCommitGraph().orElse(EMPTY)
-                                       : EMPTY;
+                       try {
+                               commitGraph = reader != null
+                                               ? reader.getCommitGraph().orElse(EMPTY)
+                                               : EMPTY;
+                       } catch (IOException e) {
+                               commitGraph = EMPTY;
+                       }
                }
                return commitGraph;
        }