mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-05 20:55:05 +00:00
index: move IndexSegment trait to "composite" module
Perhaps, this is the most controversial part. It could be moved to new "segment" module (or something like "common"), but I think IndexSegment can be considered a trait that enables the CompositeIndex abstraction.
This commit is contained in:
parent
b89ae7c0b5
commit
5121e1f4e9
5 changed files with 42 additions and 49 deletions
|
@ -21,16 +21,48 @@ use std::sync::Arc;
|
|||
|
||||
use itertools::Itertools;
|
||||
|
||||
use super::entry::{IndexEntry, IndexPosition, IndexPositionByGeneration};
|
||||
use super::entry::{IndexEntry, IndexPosition, IndexPositionByGeneration, SmallIndexPositionsVec};
|
||||
use super::readonly::ReadonlyIndexSegment;
|
||||
use super::rev_walk::RevWalk;
|
||||
use super::IndexSegment;
|
||||
use crate::backend::{CommitId, ObjectId};
|
||||
use crate::backend::{ChangeId, CommitId, ObjectId};
|
||||
use crate::index::{HexPrefix, Index, PrefixResolution};
|
||||
use crate::revset::{ResolvedExpression, Revset, RevsetEvaluationError};
|
||||
use crate::store::Store;
|
||||
use crate::{backend, default_revset_engine};
|
||||
|
||||
pub(super) trait IndexSegment: Send + Sync {
|
||||
fn segment_num_parent_commits(&self) -> u32;
|
||||
|
||||
fn segment_num_commits(&self) -> u32;
|
||||
|
||||
fn segment_parent_file(&self) -> Option<&Arc<ReadonlyIndexSegment>>;
|
||||
|
||||
fn segment_name(&self) -> Option<String>;
|
||||
|
||||
fn segment_commit_id_to_pos(&self, commit_id: &CommitId) -> Option<IndexPosition>;
|
||||
|
||||
/// Suppose the given `commit_id` exists, returns the positions of the
|
||||
/// previous and next commit ids in lexicographical order.
|
||||
fn segment_commit_id_to_neighbor_positions(
|
||||
&self,
|
||||
commit_id: &CommitId,
|
||||
) -> (Option<IndexPosition>, Option<IndexPosition>);
|
||||
|
||||
fn segment_resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution<CommitId>;
|
||||
|
||||
fn segment_generation_number(&self, local_pos: u32) -> u32;
|
||||
|
||||
fn segment_commit_id(&self, local_pos: u32) -> CommitId;
|
||||
|
||||
fn segment_change_id(&self, local_pos: u32) -> ChangeId;
|
||||
|
||||
fn segment_num_parents(&self, local_pos: u32) -> u32;
|
||||
|
||||
fn segment_parent_positions(&self, local_pos: u32) -> SmallIndexPositionsVec;
|
||||
|
||||
fn segment_entry_by_pos(&self, pos: IndexPosition, local_pos: u32) -> IndexEntry;
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct CompositeIndex<'a>(&'a dyn IndexSegment);
|
||||
|
||||
|
|
|
@ -20,8 +20,7 @@ use std::hash::{Hash, Hasher};
|
|||
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use super::composite::CompositeIndex;
|
||||
use super::IndexSegment;
|
||||
use super::composite::{CompositeIndex, IndexSegment};
|
||||
use crate::backend::{ChangeId, CommitId, ObjectId};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
|
||||
|
|
|
@ -21,66 +21,30 @@ mod readonly;
|
|||
mod rev_walk;
|
||||
mod store;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
pub use self::composite::{CompositeIndex, IndexLevelStats, IndexStats};
|
||||
use self::entry::SmallIndexPositionsVec;
|
||||
pub use self::entry::{IndexEntry, IndexEntryByPosition, IndexPosition};
|
||||
pub use self::mutable::DefaultMutableIndex;
|
||||
pub use self::readonly::DefaultReadonlyIndex;
|
||||
use self::readonly::ReadonlyIndexSegment;
|
||||
pub use self::rev_walk::{
|
||||
RevWalk, RevWalkDescendants, RevWalkDescendantsGenerationRange, RevWalkGenerationRange,
|
||||
};
|
||||
pub use self::store::{DefaultIndexStore, DefaultIndexStoreError, IndexLoadError};
|
||||
use crate::backend::{ChangeId, CommitId};
|
||||
use crate::index::{HexPrefix, PrefixResolution};
|
||||
|
||||
trait IndexSegment: Send + Sync {
|
||||
fn segment_num_parent_commits(&self) -> u32;
|
||||
|
||||
fn segment_num_commits(&self) -> u32;
|
||||
|
||||
fn segment_parent_file(&self) -> Option<&Arc<ReadonlyIndexSegment>>;
|
||||
|
||||
fn segment_name(&self) -> Option<String>;
|
||||
|
||||
fn segment_commit_id_to_pos(&self, commit_id: &CommitId) -> Option<IndexPosition>;
|
||||
|
||||
/// Suppose the given `commit_id` exists, returns the positions of the
|
||||
/// previous and next commit ids in lexicographical order.
|
||||
fn segment_commit_id_to_neighbor_positions(
|
||||
&self,
|
||||
commit_id: &CommitId,
|
||||
) -> (Option<IndexPosition>, Option<IndexPosition>);
|
||||
|
||||
fn segment_resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution<CommitId>;
|
||||
|
||||
fn segment_generation_number(&self, local_pos: u32) -> u32;
|
||||
|
||||
fn segment_commit_id(&self, local_pos: u32) -> CommitId;
|
||||
|
||||
fn segment_change_id(&self, local_pos: u32) -> ChangeId;
|
||||
|
||||
fn segment_num_parents(&self, local_pos: u32) -> u32;
|
||||
|
||||
fn segment_parent_positions(&self, local_pos: u32) -> SmallIndexPositionsVec;
|
||||
|
||||
fn segment_entry_by_pos(&self, pos: IndexPosition, local_pos: u32) -> IndexEntry;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::ops::Range;
|
||||
use std::sync::Arc;
|
||||
|
||||
use itertools::Itertools;
|
||||
use smallvec::smallvec_inline;
|
||||
use test_case::test_case;
|
||||
|
||||
use super::composite::IndexSegment;
|
||||
use super::entry::SmallIndexPositionsVec;
|
||||
use super::mutable::MutableIndexSegment;
|
||||
use super::*;
|
||||
use crate::backend::{ChangeId, CommitId, ObjectId};
|
||||
use crate::index::Index;
|
||||
use crate::index::{HexPrefix, Index, PrefixResolution};
|
||||
|
||||
/// Generator of unique 16-byte ChangeId excluding root id
|
||||
fn change_id_generator() -> impl FnMut() -> ChangeId {
|
||||
|
|
|
@ -30,11 +30,10 @@ use itertools::Itertools;
|
|||
use smallvec::SmallVec;
|
||||
use tempfile::NamedTempFile;
|
||||
|
||||
use super::composite::CompositeIndex;
|
||||
use super::composite::{CompositeIndex, IndexSegment};
|
||||
use super::entry::{IndexEntry, IndexPosition, SmallIndexPositionsVec};
|
||||
use super::readonly::{DefaultReadonlyIndex, ReadonlyIndexSegment};
|
||||
use super::store::IndexLoadError;
|
||||
use super::IndexSegment;
|
||||
use crate::backend::{ChangeId, CommitId, ObjectId};
|
||||
use crate::commit::Commit;
|
||||
use crate::file_util::persist_content_addressed_temp_file;
|
||||
|
|
|
@ -25,11 +25,10 @@ use std::sync::Arc;
|
|||
use byteorder::{LittleEndian, ReadBytesExt};
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use super::composite::CompositeIndex;
|
||||
use super::composite::{CompositeIndex, IndexSegment};
|
||||
use super::entry::{IndexEntry, IndexPosition, SmallIndexPositionsVec};
|
||||
use super::mutable::DefaultMutableIndex;
|
||||
use super::store::IndexLoadError;
|
||||
use super::IndexSegment;
|
||||
use crate::backend::{ChangeId, CommitId, ObjectId};
|
||||
use crate::index::{HexPrefix, Index, MutableIndex, PrefixResolution, ReadonlyIndex};
|
||||
use crate::revset::{ResolvedExpression, Revset, RevsetEvaluationError};
|
||||
|
|
Loading…
Reference in a new issue