From 0f6a7418f2e01270e303f2acd374f16d61d16ae7 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Thu, 21 Dec 2023 09:38:16 +0900 Subject: [PATCH] index: propagate store error from reindexing function If the error is permanent (because the repo predates the no-gc-ref fix for example), there's no easy way to recover. Still, panicking in this function seems wrong. --- lib/src/default_index/store.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/src/default_index/store.rs b/lib/src/default_index/store.rs index 4c59d709c..af60248ff 100644 --- a/lib/src/default_index/store.rs +++ b/lib/src/default_index/store.rs @@ -26,7 +26,7 @@ use thiserror::Error; use super::mutable::DefaultMutableIndex; use super::readonly::{DefaultReadonlyIndex, ReadonlyIndexLoadError, ReadonlyIndexSegment}; -use crate::backend::{CommitId, ObjectId}; +use crate::backend::{BackendError, CommitId, ObjectId}; use crate::commit::CommitByCommitterTimestamp; use crate::dag_walk; use crate::file_util::persist_content_addressed_temp_file; @@ -50,6 +50,8 @@ pub enum DefaultIndexStoreError { LoadIndex(ReadonlyIndexLoadError), #[error("Failed to write commit index file: {0}")] SaveIndex(#[source] io::Error), + #[error("Failed to index commits: {0}")] + IndexCommits(#[source] BackendError), #[error(transparent)] OpStore(#[from] OpStoreError), } @@ -159,21 +161,22 @@ impl DefaultIndexStore { .as_ref() .map_or(false, |segment| segment.as_composite().has_id(id)) }; - let commits = dag_walk::topo_order_reverse_ord( + let commits = dag_walk::topo_order_reverse_ord_ok( new_heads .iter() .filter(|&id| !parent_file_has_id(id)) - .map(|id| store.get_commit(id).unwrap()) - .map(CommitByCommitterTimestamp), + .map(|id| store.get_commit(id)) + .map_ok(CommitByCommitterTimestamp), |CommitByCommitterTimestamp(commit)| commit.id().clone(), |CommitByCommitterTimestamp(commit)| { itertools::chain(commit.parent_ids(), commit.predecessor_ids()) .filter(|&id| !parent_file_has_id(id)) - .map(|id| store.get_commit(id).unwrap()) - .map(CommitByCommitterTimestamp) + .map(|id| store.get_commit(id)) + .map_ok(CommitByCommitterTimestamp) .collect_vec() }, - ); + ) + .map_err(DefaultIndexStoreError::IndexCommits)?; for CommitByCommitterTimestamp(commit) in commits.iter().rev() { mutable_index.add_commit(commit); }