diff --git a/lib/src/default_index_store.rs b/lib/src/default_index_store.rs index ad4e98773..62b49d8f8 100644 --- a/lib/src/default_index_store.rs +++ b/lib/src/default_index_store.rs @@ -493,6 +493,10 @@ impl MutableIndexImpl { } } + pub fn as_composite(&self) -> CompositeIndex { + CompositeIndex(self) + } + pub(crate) fn add_commit_data( &mut self, commit_id: CommitId, @@ -509,7 +513,7 @@ impl MutableIndexImpl { parent_positions: vec![], }; for parent_id in parent_ids { - let parent_entry = self + let parent_entry = CompositeIndex(self) .entry_by_id(parent_id) .expect("parent commit is not indexed"); entry.generation_number = max( @@ -699,10 +703,6 @@ impl Index for MutableIndexImpl { CompositeIndex(self).resolve_prefix(prefix) } - fn entry_by_id(&self, commit_id: &CommitId) -> Option { - CompositeIndex(self).entry_by_id(commit_id) - } - fn has_id(&self, commit_id: &CommitId) -> bool { CompositeIndex(self).has_id(commit_id) } @@ -953,7 +953,7 @@ impl<'a> CompositeIndex<'a> { }) } - pub(crate) fn entry_by_id(&self, commit_id: &CommitId) -> Option> { + pub fn entry_by_id(&self, commit_id: &CommitId) -> Option> { self.commit_id_to_pos(commit_id) .map(|pos| self.entry_by_pos(pos)) } @@ -1781,10 +1781,6 @@ impl Index for ReadonlyIndexImpl { CompositeIndex(self).resolve_prefix(prefix) } - fn entry_by_id(&self, commit_id: &CommitId) -> Option { - CompositeIndex(self).entry_by_id(commit_id) - } - fn has_id(&self, commit_id: &CommitId) -> bool { CompositeIndex(self).has_id(commit_id) } diff --git a/lib/src/default_revset_engine.rs b/lib/src/default_revset_engine.rs index f658a73f4..439304ce9 100644 --- a/lib/src/default_revset_engine.rs +++ b/lib/src/default_revset_engine.rs @@ -944,7 +944,6 @@ mod tests { use super::*; use crate::backend::{ChangeId, CommitId, ObjectId}; use crate::default_index_store::MutableIndexImpl; - use crate::index::Index; #[test] fn test_id_index_resolve_prefix() { @@ -1073,7 +1072,7 @@ mod tests { index.add_commit_data(id_3.clone(), new_change_id(), &[id_2.clone()]); index.add_commit_data(id_4.clone(), new_change_id(), &[id_3.clone()]); - let get_entry = |id: &CommitId| index.entry_by_id(id).unwrap(); + let get_entry = |id: &CommitId| index.as_composite().entry_by_id(id).unwrap(); let make_entries = |ids: &[&CommitId]| ids.iter().map(|id| get_entry(id)).collect_vec(); let make_set = |ids: &[&CommitId]| -> Box { let index_entries = make_entries(ids); diff --git a/lib/src/index.rs b/lib/src/index.rs index 16209835d..5af6a6ce4 100644 --- a/lib/src/index.rs +++ b/lib/src/index.rs @@ -20,7 +20,7 @@ use thiserror::Error; use crate::backend::{CommitId, ObjectId}; use crate::commit::Commit; -use crate::default_index_store::{IndexEntry, RevWalk}; +use crate::default_index_store::RevWalk; use crate::op_store::OperationId; use crate::operation::Operation; use crate::revset::{ResolvedExpression, Revset, RevsetEvaluationError}; @@ -53,8 +53,6 @@ pub trait Index: Send + Sync { fn resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution; - fn entry_by_id(&self, commit_id: &CommitId) -> Option; - fn has_id(&self, commit_id: &CommitId) -> bool; fn is_ancestor(&self, ancestor_id: &CommitId, descendant_id: &CommitId) -> bool; diff --git a/lib/tests/test_index.rs b/lib/tests/test_index.rs index 69c2f253a..f34a70a96 100644 --- a/lib/tests/test_index.rs +++ b/lib/tests/test_index.rs @@ -36,7 +36,11 @@ fn child_commit<'repo>( // Helper just to reduce line wrapping fn generation_number(index: &ReadonlyIndexImpl, commit_id: &CommitId) -> u32 { - index.entry_by_id(commit_id).unwrap().generation_number() + index + .as_composite() + .entry_by_id(commit_id) + .unwrap() + .generation_number() } #[test_case(false ; "local backend")]