mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-05 20:55:05 +00:00
index: move IndexLoadError to "readonly" module, rename accordingly
I thought IndexLoadError and DefaultIndexStoreError would represent "load" and "store" failures respectively, but they aren't. Actually, DefaultIndexStoreError is the store-level error, and IndexLoadError should be wrapped in it.
This commit is contained in:
parent
b5de16007e
commit
31b6e93c6e
4 changed files with 20 additions and 20 deletions
|
@ -24,11 +24,11 @@ mod store;
|
|||
pub use self::composite::{AsCompositeIndex, CompositeIndex, IndexLevelStats, IndexStats};
|
||||
pub use self::entry::{IndexEntry, IndexPosition};
|
||||
pub use self::mutable::DefaultMutableIndex;
|
||||
pub use self::readonly::DefaultReadonlyIndex;
|
||||
pub use self::readonly::{DefaultReadonlyIndex, ReadonlyIndexLoadError};
|
||||
pub use self::rev_walk::{
|
||||
RevWalk, RevWalkDescendants, RevWalkDescendantsGenerationRange, RevWalkGenerationRange,
|
||||
};
|
||||
pub use self::store::{DefaultIndexStore, DefaultIndexStoreError, IndexLoadError};
|
||||
pub use self::store::{DefaultIndexStore, DefaultIndexStoreError};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
|
|
@ -32,8 +32,7 @@ use tempfile::NamedTempFile;
|
|||
|
||||
use super::composite::{AsCompositeIndex, CompositeIndex, IndexSegment};
|
||||
use super::entry::{IndexEntry, IndexPosition, SmallIndexPositionsVec};
|
||||
use super::readonly::{DefaultReadonlyIndex, ReadonlyIndexSegment};
|
||||
use super::store::IndexLoadError;
|
||||
use super::readonly::{DefaultReadonlyIndex, ReadonlyIndexLoadError, ReadonlyIndexSegment};
|
||||
use crate::backend::{ChangeId, CommitId, ObjectId};
|
||||
use crate::commit::Commit;
|
||||
use crate::file_util::persist_content_addressed_temp_file;
|
||||
|
@ -302,10 +301,10 @@ impl MutableIndexSegment {
|
|||
change_id_length,
|
||||
)
|
||||
.map_err(|err| match err {
|
||||
IndexLoadError::IndexCorrupt(err) => {
|
||||
ReadonlyIndexLoadError::IndexCorrupt(err) => {
|
||||
panic!("Just-created index file is corrupt: {err}")
|
||||
}
|
||||
IndexLoadError::IoError(err) => err,
|
||||
ReadonlyIndexLoadError::IoError(err) => err,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,23 +18,32 @@ use std::any::Any;
|
|||
use std::cmp::Ordering;
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::fs::File;
|
||||
use std::io;
|
||||
use std::io::Read;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
use byteorder::{LittleEndian, ReadBytesExt};
|
||||
use smallvec::SmallVec;
|
||||
use thiserror::Error;
|
||||
|
||||
use super::composite::{AsCompositeIndex, CompositeIndex, IndexSegment};
|
||||
use super::entry::{IndexEntry, IndexPosition, SmallIndexPositionsVec};
|
||||
use super::mutable::DefaultMutableIndex;
|
||||
use super::store::IndexLoadError;
|
||||
use crate::backend::{ChangeId, CommitId, ObjectId};
|
||||
use crate::default_revset_engine;
|
||||
use crate::index::{HexPrefix, Index, MutableIndex, PrefixResolution, ReadonlyIndex};
|
||||
use crate::revset::{ResolvedExpression, Revset, RevsetEvaluationError};
|
||||
use crate::store::Store;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ReadonlyIndexLoadError {
|
||||
#[error("Index file '{0}' is corrupt.")]
|
||||
IndexCorrupt(String),
|
||||
#[error("I/O error while loading index file: {0}")]
|
||||
IoError(#[from] io::Error),
|
||||
}
|
||||
|
||||
struct CommitGraphEntry<'a> {
|
||||
data: &'a [u8],
|
||||
commit_id_length: usize,
|
||||
|
@ -166,7 +175,7 @@ impl ReadonlyIndexSegment {
|
|||
name: String,
|
||||
commit_id_length: usize,
|
||||
change_id_length: usize,
|
||||
) -> Result<Arc<ReadonlyIndexSegment>, IndexLoadError> {
|
||||
) -> Result<Arc<ReadonlyIndexSegment>, ReadonlyIndexLoadError> {
|
||||
let parent_filename_len = file.read_u32::<LittleEndian>()?;
|
||||
let num_parent_commits;
|
||||
let maybe_parent_file;
|
||||
|
@ -200,7 +209,7 @@ impl ReadonlyIndexSegment {
|
|||
let parent_overflow_size = (num_parent_overflow_entries as usize) * 4;
|
||||
let expected_size = graph_size + lookup_size + parent_overflow_size;
|
||||
if data.len() != expected_size {
|
||||
return Err(IndexLoadError::IndexCorrupt(name));
|
||||
return Err(ReadonlyIndexLoadError::IndexCorrupt(name));
|
||||
}
|
||||
Ok(Arc::new(ReadonlyIndexSegment {
|
||||
parent_file: maybe_parent_file,
|
||||
|
|
|
@ -26,7 +26,7 @@ use tempfile::NamedTempFile;
|
|||
use thiserror::Error;
|
||||
|
||||
use super::mutable::DefaultMutableIndex;
|
||||
use super::readonly::{DefaultReadonlyIndex, ReadonlyIndexSegment};
|
||||
use super::readonly::{DefaultReadonlyIndex, ReadonlyIndexLoadError, ReadonlyIndexSegment};
|
||||
use crate::backend::{CommitId, ObjectId};
|
||||
use crate::commit::CommitByCommitterTimestamp;
|
||||
use crate::dag_walk;
|
||||
|
@ -38,14 +38,6 @@ use crate::op_store::{OpStoreError, OperationId};
|
|||
use crate::operation::Operation;
|
||||
use crate::store::Store;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum IndexLoadError {
|
||||
#[error("Index file '{0}' is corrupt.")]
|
||||
IndexCorrupt(String),
|
||||
#[error("I/O error while loading index file: {0}")]
|
||||
IoError(#[from] io::Error),
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum DefaultIndexStoreError {
|
||||
#[error("Failed to associate commit index file with a operation {op_id:?}: {source}")]
|
||||
|
@ -93,7 +85,7 @@ impl DefaultIndexStore {
|
|||
commit_id_length: usize,
|
||||
change_id_length: usize,
|
||||
op_id: &OperationId,
|
||||
) -> Result<Arc<ReadonlyIndexSegment>, IndexLoadError> {
|
||||
) -> Result<Arc<ReadonlyIndexSegment>, ReadonlyIndexLoadError> {
|
||||
let op_id_file = self.dir.join("operations").join(op_id.hex());
|
||||
let buf = fs::read(op_id_file).unwrap();
|
||||
let index_file_id_hex = String::from_utf8(buf).unwrap();
|
||||
|
@ -248,7 +240,7 @@ impl IndexStore for DefaultIndexStore {
|
|||
store.change_id_length(),
|
||||
op.id(),
|
||||
) {
|
||||
Err(IndexLoadError::IndexCorrupt(_)) => {
|
||||
Err(ReadonlyIndexLoadError::IndexCorrupt(_)) => {
|
||||
// If the index was corrupt (maybe it was written in a different format),
|
||||
// we just reindex.
|
||||
// TODO: Move this message to a callback or something.
|
||||
|
|
Loading…
Reference in a new issue