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 <xingkhuang@google.com>
Change-Id: I38eeacff76c7f926b6dfb192d1e5916e40770024
This commit is contained in:
Xing Huang 2023-02-06 14:18:16 -06:00 committed by Ivan Frade
parent e8042d02e6
commit eccae7cf0b
2 changed files with 12 additions and 4 deletions

View File

@ -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<CommitGraph> getCommitGraph() {
public Optional<CommitGraph> getCommitGraph() throws IOException {
return Optional.empty();
}
@ -661,7 +664,7 @@ public BitmapIndex getBitmapIndex() throws IOException {
}
@Override
public Optional<CommitGraph> getCommitGraph() {
public Optional<CommitGraph> getCommitGraph() throws IOException{
return delegate().getCommitGraph();
}

View File

@ -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;
}