mirror of
https://github.com/martinvonz/jj.git
synced 2025-05-14 11:44:27 +00:00
index: add wrapper functions to DefaultMutableIndex to remove pub(super) field
into_segment() could be added instead of save_in(), but I decided to wrap save_in(). save_in() may squash ancestor files, so it could be considered an index-level operation.
This commit is contained in:
parent
5aeeb5f723
commit
fbec16b49f
@ -33,7 +33,6 @@ use smallvec::SmallVec;
|
||||
|
||||
pub use self::composite::{CompositeIndex, IndexLevelStats, IndexStats};
|
||||
pub use self::mutable::DefaultMutableIndex;
|
||||
use self::mutable::MutableIndexSegment;
|
||||
pub use self::rev_walk::{
|
||||
RevWalk, RevWalkDescendants, RevWalkDescendantsGenerationRange, RevWalkGenerationRange,
|
||||
};
|
||||
@ -171,8 +170,7 @@ impl ReadonlyIndex for DefaultReadonlyIndex {
|
||||
}
|
||||
|
||||
fn start_modification(&self) -> Box<dyn MutableIndex> {
|
||||
let mutable_segment = MutableIndexSegment::incremental(self.0.clone());
|
||||
Box::new(DefaultMutableIndex(mutable_segment))
|
||||
Box::new(DefaultMutableIndex::incremental(self.0.clone()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -602,6 +600,7 @@ mod tests {
|
||||
use smallvec::smallvec_inline;
|
||||
use test_case::test_case;
|
||||
|
||||
use super::mutable::MutableIndexSegment;
|
||||
use super::*;
|
||||
use crate::backend::{ChangeId, CommitId, ObjectId};
|
||||
use crate::index::Index;
|
||||
|
@ -395,7 +395,7 @@ impl IndexSegment for MutableIndexSegment {
|
||||
}
|
||||
|
||||
/// In-memory mutable records for the on-disk commit index backend.
|
||||
pub struct DefaultMutableIndex(pub(super) MutableIndexSegment);
|
||||
pub struct DefaultMutableIndex(MutableIndexSegment);
|
||||
|
||||
impl DefaultMutableIndex {
|
||||
#[cfg(test)]
|
||||
@ -404,6 +404,11 @@ impl DefaultMutableIndex {
|
||||
DefaultMutableIndex(mutable_segment)
|
||||
}
|
||||
|
||||
pub(super) fn incremental(parent_file: Arc<ReadonlyIndexSegment>) -> Self {
|
||||
let mutable_segment = MutableIndexSegment::incremental(parent_file);
|
||||
DefaultMutableIndex(mutable_segment)
|
||||
}
|
||||
|
||||
pub fn as_composite(&self) -> CompositeIndex {
|
||||
self.0.as_composite()
|
||||
}
|
||||
@ -417,6 +422,10 @@ impl DefaultMutableIndex {
|
||||
) {
|
||||
self.0.add_commit_data(commit_id, change_id, parent_ids);
|
||||
}
|
||||
|
||||
pub(super) fn save_in(self, dir: PathBuf) -> io::Result<Arc<ReadonlyIndexSegment>> {
|
||||
self.0.save_in(dir)
|
||||
}
|
||||
}
|
||||
|
||||
impl Index for DefaultMutableIndex {
|
||||
|
@ -248,7 +248,7 @@ impl IndexStore for DefaultIndexStore {
|
||||
.into_any()
|
||||
.downcast::<DefaultMutableIndex>()
|
||||
.expect("index to merge in must be a DefaultMutableIndex");
|
||||
let index_segment = index.0.save_in(self.dir.clone()).map_err(|err| {
|
||||
let index_segment = index.save_in(self.dir.clone()).map_err(|err| {
|
||||
IndexWriteError::Other(format!("Failed to write commit index file: {err}"))
|
||||
})?;
|
||||
self.associate_file_with_operation(&index_segment, op_id)
|
||||
|
Loading…
x
Reference in New Issue
Block a user