From fbec16b49f8fca28b7ecaa9b6c1e202a32b88de5 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Mon, 11 Dec 2023 20:06:57 +0900 Subject: [PATCH] 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. --- lib/src/default_index/mod.rs | 5 ++--- lib/src/default_index/mutable.rs | 11 ++++++++++- lib/src/default_index/store.rs | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/src/default_index/mod.rs b/lib/src/default_index/mod.rs index 8c3cd1b9e..52ee6a074 100644 --- a/lib/src/default_index/mod.rs +++ b/lib/src/default_index/mod.rs @@ -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 { - 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; diff --git a/lib/src/default_index/mutable.rs b/lib/src/default_index/mutable.rs index ae83ec54c..df1b281e2 100644 --- a/lib/src/default_index/mutable.rs +++ b/lib/src/default_index/mutable.rs @@ -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) -> 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> { + self.0.save_in(dir) + } } impl Index for DefaultMutableIndex { diff --git a/lib/src/default_index/store.rs b/lib/src/default_index/store.rs index 7c4bc4c26..edb12226d 100644 --- a/lib/src/default_index/store.rs +++ b/lib/src/default_index/store.rs @@ -248,7 +248,7 @@ impl IndexStore for DefaultIndexStore { .into_any() .downcast::() .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)