diff --git a/lib/src/default_index_store.rs b/lib/src/default_index_store.rs index 5221c025e3..16236534cc 100644 --- a/lib/src/default_index_store.rs +++ b/lib/src/default_index_store.rs @@ -136,14 +136,14 @@ impl DefaultIndexStore { match parent_op_id { None => { maybe_parent_file = None; - data = MutableIndexImpl::full(commit_id_length, change_id_length); + data = MutableIndexSegment::full(commit_id_length, change_id_length); } Some(parent_op_id) => { let parent_file = self .load_index_at_operation(commit_id_length, change_id_length, &parent_op_id) .unwrap(); maybe_parent_file = Some(parent_file.clone()); - data = MutableIndexImpl::incremental(parent_file) + data = MutableIndexSegment::incremental(parent_file) } } @@ -399,7 +399,7 @@ impl ReadonlyIndex for DefaultReadonlyIndex { } fn start_modification(&self) -> Box { - let mutable_segment = MutableIndexImpl::incremental(self.0.clone()); + let mutable_segment = MutableIndexSegment::incremental(self.0.clone()); Box::new(DefaultMutableIndex(mutable_segment)) } } @@ -427,7 +427,7 @@ struct MutableGraphEntry { parent_positions: SmallIndexPositionsVec, } -struct MutableIndexImpl { +struct MutableIndexSegment { parent_file: Option>, num_parent_commits: u32, commit_id_length: usize, @@ -436,7 +436,7 @@ struct MutableIndexImpl { lookup: BTreeMap, } -impl MutableIndexImpl { +impl MutableIndexSegment { fn full(commit_id_length: usize, change_id_length: usize) -> Self { Self { parent_file: None, @@ -615,7 +615,7 @@ impl MutableIndexImpl { /// If the MutableIndex has more than half the commits of its parent /// ReadonlyIndex, return MutableIndex with the commits from both. This /// is done recursively, so the stack of index files has O(log n) files. - fn maybe_squash_with_ancestors(self) -> MutableIndexImpl { + fn maybe_squash_with_ancestors(self) -> MutableIndexSegment { let mut num_new_commits = self.segment_num_commits(); let mut files_to_squash = vec![]; let mut maybe_parent_file = self.parent_file.clone(); @@ -626,7 +626,7 @@ impl MutableIndexImpl { // TODO: We should probably also squash if the parent file has less than N // commits, regardless of how many (few) are in `self`. if 2 * num_new_commits < parent_file.segment_num_commits() { - squashed = MutableIndexImpl::incremental(parent_file); + squashed = MutableIndexSegment::incremental(parent_file); break; } num_new_commits += parent_file.segment_num_commits(); @@ -634,7 +634,8 @@ impl MutableIndexImpl { maybe_parent_file = parent_file.parent_file.clone(); } None => { - squashed = MutableIndexImpl::full(self.commit_id_length, self.change_id_length); + squashed = + MutableIndexSegment::full(self.commit_id_length, self.change_id_length); break; } } @@ -687,12 +688,12 @@ impl MutableIndexImpl { } /// In-memory mutable records for the on-disk commit index backend. -pub struct DefaultMutableIndex(MutableIndexImpl); +pub struct DefaultMutableIndex(MutableIndexSegment); impl DefaultMutableIndex { #[cfg(test)] pub(crate) fn full(commit_id_length: usize, change_id_length: usize) -> Self { - let mutable_segment = MutableIndexImpl::full(commit_id_length, change_id_length); + let mutable_segment = MutableIndexSegment::full(commit_id_length, change_id_length); DefaultMutableIndex(mutable_segment) } @@ -1703,7 +1704,7 @@ impl IndexSegment for ReadonlyIndexSegment { } } -impl IndexSegment for MutableIndexImpl { +impl IndexSegment for MutableIndexSegment { fn segment_num_parent_commits(&self) -> u32 { self.num_parent_commits } @@ -2034,7 +2035,7 @@ mod tests { #[test_case(true; "file")] fn index_empty(on_disk: bool) { let temp_dir = testutils::new_temp_dir(); - let mutable_segment = MutableIndexImpl::full(3, 16); + let mutable_segment = MutableIndexSegment::full(3, 16); let index_segment: Box = if on_disk { let saved_index = mutable_segment.save_in(temp_dir.path().to_owned()).unwrap(); Box::new(Arc::try_unwrap(saved_index).unwrap()) @@ -2062,7 +2063,7 @@ mod tests { fn index_root_commit(on_disk: bool) { let temp_dir = testutils::new_temp_dir(); let mut new_change_id = change_id_generator(); - let mut mutable_segment = MutableIndexImpl::full(3, 16); + let mut mutable_segment = MutableIndexSegment::full(3, 16); let id_0 = CommitId::from_hex("000000"); let change_id0 = new_change_id(); mutable_segment.add_commit_data(id_0.clone(), change_id0.clone(), &[]); @@ -2114,7 +2115,7 @@ mod tests { fn index_multiple_commits(incremental: bool, on_disk: bool) { let temp_dir = testutils::new_temp_dir(); let mut new_change_id = change_id_generator(); - let mut mutable_segment = MutableIndexImpl::full(3, 16); + let mut mutable_segment = MutableIndexSegment::full(3, 16); // 5 // |\ // 4 | 3 @@ -2139,7 +2140,7 @@ mod tests { // now and build the remainder as another segment on top. if incremental { let initial_file = mutable_segment.save_in(temp_dir.path().to_owned()).unwrap(); - mutable_segment = MutableIndexImpl::incremental(initial_file); + mutable_segment = MutableIndexSegment::incremental(initial_file); } let id_3 = CommitId::from_hex("333333"); @@ -2226,7 +2227,7 @@ mod tests { fn index_many_parents(on_disk: bool) { let temp_dir = testutils::new_temp_dir(); let mut new_change_id = change_id_generator(); - let mut mutable_segment = MutableIndexImpl::full(3, 16); + let mut mutable_segment = MutableIndexSegment::full(3, 16); // 6 // /|\ // / | \ @@ -2290,7 +2291,7 @@ mod tests { fn resolve_prefix() { let temp_dir = testutils::new_temp_dir(); let mut new_change_id = change_id_generator(); - let mut mutable_segment = MutableIndexImpl::full(3, 16); + let mut mutable_segment = MutableIndexSegment::full(3, 16); // Create some commits with different various common prefixes. let id_0 = CommitId::from_hex("000000"); @@ -2302,7 +2303,7 @@ mod tests { // Write the first three commits to one file and build the remainder on top. let initial_file = mutable_segment.save_in(temp_dir.path().to_owned()).unwrap(); - mutable_segment = MutableIndexImpl::incremental(initial_file); + mutable_segment = MutableIndexSegment::incremental(initial_file); let id_3 = CommitId::from_hex("055444"); let id_4 = CommitId::from_hex("055555"); @@ -2362,7 +2363,7 @@ mod tests { fn neighbor_commit_ids() { let temp_dir = testutils::new_temp_dir(); let mut new_change_id = change_id_generator(); - let mut mutable_segment = MutableIndexImpl::full(3, 16); + let mut mutable_segment = MutableIndexSegment::full(3, 16); // Create some commits with different various common prefixes. let id_0 = CommitId::from_hex("000001"); @@ -2374,7 +2375,7 @@ mod tests { // Write the first three commits to one file and build the remainder on top. let initial_file = mutable_segment.save_in(temp_dir.path().to_owned()).unwrap(); - mutable_segment = MutableIndexImpl::incremental(initial_file.clone()); + mutable_segment = MutableIndexSegment::incremental(initial_file.clone()); let id_3 = CommitId::from_hex("055444"); let id_4 = CommitId::from_hex("055555"); @@ -2490,7 +2491,7 @@ mod tests { fn shortest_unique_commit_id_prefix() { let temp_dir = testutils::new_temp_dir(); let mut new_change_id = change_id_generator(); - let mut mutable_segment = MutableIndexImpl::full(3, 16); + let mut mutable_segment = MutableIndexSegment::full(3, 16); // Create some commits with different various common prefixes. let id_0 = CommitId::from_hex("000001"); @@ -2502,7 +2503,7 @@ mod tests { // Write the first three commits to one file and build the remainder on top. let initial_file = mutable_segment.save_in(temp_dir.path().to_owned()).unwrap(); - mutable_segment = MutableIndexImpl::incremental(initial_file); + mutable_segment = MutableIndexSegment::incremental(initial_file); let id_3 = CommitId::from_hex("055444"); let id_4 = CommitId::from_hex("055555");