From eccae7cf0bb1ffd4425b6961597b28a8510fc42c Mon Sep 17 00:00:00 2001 From: Xing Huang Date: Mon, 6 Feb 2023 14:18:16 -0600 Subject: [PATCH] ObjectReader: Allow getCommitGraph to throw IOException 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 Change-Id: I38eeacff76c7f926b6dfb192d1e5916e40770024 --- .../src/org/eclipse/jgit/lib/ObjectReader.java | 7 +++++-- .../src/org/eclipse/jgit/revwalk/RevWalk.java | 9 +++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java index ae0cf42b1..69b2b5104 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java @@ -512,9 +512,12 @@ public ObjectReachabilityChecker createObjectReachabilityChecker( * (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 getCommitGraph() { + public Optional getCommitGraph() throws IOException { return Optional.empty(); } @@ -661,7 +664,7 @@ public BitmapIndex getBitmapIndex() throws IOException { } @Override - public Optional getCommitGraph() { + public Optional getCommitGraph() throws IOException{ return delegate().getCommitGraph(); } 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 a66e7c86b..9da710556 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java @@ -1173,8 +1173,13 @@ byte[] getCachedBytes(RevObject obj, ObjectLoader ldr) @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; }