ok/jj
1
0
Fork 0
forked from mirrors/jj

index: remove redundant stat() of operation link file, handle error instead

This wouldn't matter in practice, but the operation link file could be deleted
after testing the existence.
This commit is contained in:
Yuya Nishihara 2023-12-28 18:28:33 +09:00
parent 96d0e776ad
commit 3d68601c01

View file

@ -288,14 +288,16 @@ impl IndexStore for DefaultIndexStore {
op: &Operation,
store: &Arc<Store>,
) -> Result<Box<dyn ReadonlyIndex>, IndexReadError> {
let op_id_hex = op.id().hex();
let op_id_file = self.dir.join("operations").join(op_id_hex);
let index_segment = if op_id_file.exists() {
match self.load_index_segments_at_operation(
let index_segment = match self.load_index_segments_at_operation(
op.id(),
store.commit_id_length(),
store.change_id_length(),
) {
Err(DefaultIndexStoreError::LoadAssociation(err))
if err.kind() == io::ErrorKind::NotFound =>
{
self.build_index_segments_at_operation(op, store)
}
Err(DefaultIndexStoreError::LoadIndex(err)) if err.is_corrupt_or_not_found() => {
// If the index was corrupt (maybe it was written in a different format),
// we just reindex.
@ -306,9 +308,6 @@ impl IndexStore for DefaultIndexStore {
}
result => result,
}
} else {
self.build_index_segments_at_operation(op, store)
}
.map_err(|err| IndexReadError(err.into()))?;
Ok(Box::new(DefaultReadonlyIndex::from_segment(index_segment)))
}