diff --git a/lib/src/default_index_store.rs b/lib/src/default_index_store.rs index d6de37a9c..3e28ad23b 100644 --- a/lib/src/default_index_store.rs +++ b/lib/src/default_index_store.rs @@ -688,10 +688,6 @@ impl MutableIndexImpl { } impl Index for MutableIndexImpl { - fn as_any(&self) -> &dyn Any { - self - } - fn shortest_unique_commit_id_prefix_len(&self, commit_id: &CommitId) -> usize { CompositeIndex(self).shortest_unique_commit_id_prefix_len(commit_id) } @@ -732,6 +728,10 @@ impl Index for MutableIndexImpl { } impl MutableIndex for MutableIndexImpl { + fn as_any(&self) -> &dyn Any { + self + } + fn into_any(self: Box) -> Box { Box::new(*self) } @@ -1976,10 +1976,6 @@ impl ReadonlyIndexImpl { } impl Index for ReadonlyIndexImpl { - fn as_any(&self) -> &dyn Any { - self - } - fn shortest_unique_commit_id_prefix_len(&self, commit_id: &CommitId) -> usize { CompositeIndex(self).shortest_unique_commit_id_prefix_len(commit_id) } diff --git a/lib/src/index.rs b/lib/src/index.rs index 892f5ecf7..0e85432d4 100644 --- a/lib/src/index.rs +++ b/lib/src/index.rs @@ -46,8 +46,6 @@ pub trait IndexStore: Send + Sync + Debug { } pub trait Index: Send + Sync { - fn as_any(&self) -> &dyn Any; - fn shortest_unique_commit_id_prefix_len(&self, commit_id: &CommitId) -> usize; fn resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution; @@ -79,6 +77,8 @@ pub trait ReadonlyIndex: Send + Sync { } pub trait MutableIndex: Any { + fn as_any(&self) -> &dyn Any; + fn into_any(self: Box) -> Box; fn as_index(&self) -> &dyn Index; diff --git a/lib/src/repo.rs b/lib/src/repo.rs index 48e3689aa..1f74ee559 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -662,6 +662,10 @@ impl MutableRepo { self.view.get_mut() } + pub fn mutable_index(&self) -> &dyn MutableIndex { + self.index.as_ref() + } + pub fn has_changes(&self) -> bool { !(self.abandoned_commits.is_empty() && self.rewritten_commits.is_empty() diff --git a/lib/tests/test_index.rs b/lib/tests/test_index.rs index 56ffc3b9f..95638d530 100644 --- a/lib/tests/test_index.rs +++ b/lib/tests/test_index.rs @@ -457,7 +457,7 @@ fn as_readonly_composite(repo: &Arc) -> CompositeIndex<'_> { } fn as_mutable_impl(repo: &MutableRepo) -> &MutableIndexImpl { - repo.index() + repo.mutable_index() .as_any() .downcast_ref::() .unwrap()