diff --git a/lib/src/default_index_store.rs b/lib/src/default_index_store.rs index 6eb90cd5a..1dc1e8a6b 100644 --- a/lib/src/default_index_store.rs +++ b/lib/src/default_index_store.rs @@ -733,7 +733,8 @@ impl Index for MutableIndexImpl { repo: &'index dyn Repo, expression: &RevsetExpression, ) -> Result + 'index>, RevsetError> { - default_revset_engine::evaluate(repo, CompositeIndex(self), expression) + let revset_impl = default_revset_engine::evaluate(repo, CompositeIndex(self), expression)?; + Ok(Box::new(revset_impl)) } } @@ -1698,6 +1699,10 @@ impl ReadonlyIndexImpl { })) } + pub fn as_composite(&self) -> CompositeIndex { + CompositeIndex(self) + } + fn name(&self) -> &str { &self.name } @@ -1806,7 +1811,8 @@ impl Index for ReadonlyIndexImpl { repo: &'index dyn Repo, expression: &RevsetExpression, ) -> Result + 'index>, RevsetError> { - default_revset_engine::evaluate(repo, CompositeIndex(self), expression) + let revset_impl = default_revset_engine::evaluate(repo, CompositeIndex(self), expression)?; + Ok(Box::new(revset_impl)) } } diff --git a/lib/src/default_revset_engine.rs b/lib/src/default_revset_engine.rs index a3b0b1bc6..161c59e36 100644 --- a/lib/src/default_revset_engine.rs +++ b/lib/src/default_revset_engine.rs @@ -51,7 +51,7 @@ trait InternalRevset<'index>: ToPredicateFn<'index> { fn iter(&self) -> Box> + '_>; } -struct RevsetImpl<'index> { +pub struct RevsetImpl<'index> { inner: Box + 'index>, index: CompositeIndex<'index>, } @@ -66,6 +66,10 @@ impl<'index> RevsetImpl<'index> { index, } } + + pub fn iter_graph_impl(&self) -> RevsetGraphIterator<'_, 'index> { + RevsetGraphIterator::new(self.inner.iter()) + } } impl<'index> Revset<'index> for RevsetImpl<'index> { @@ -491,9 +495,9 @@ pub fn evaluate<'index>( repo: &'index dyn Repo, index: CompositeIndex<'index>, expression: &RevsetExpression, -) -> Result + 'index>, RevsetError> { +) -> Result, RevsetError> { let internal_revset = internal_evaluate(repo, expression)?; - Ok(Box::new(RevsetImpl::new(internal_revset, index))) + Ok(RevsetImpl::new(internal_revset, index)) } fn internal_evaluate<'index>( diff --git a/lib/tests/test_default_revset_graph_iterator.rs b/lib/tests/test_default_revset_graph_iterator.rs index f55721920..c07ac626f 100644 --- a/lib/tests/test_default_revset_graph_iterator.rs +++ b/lib/tests/test_default_revset_graph_iterator.rs @@ -14,19 +14,22 @@ use itertools::Itertools; use jujutsu_lib::commit::Commit; -use jujutsu_lib::default_revset_graph_iterator::RevsetGraphIterator; +use jujutsu_lib::default_index_store::ReadonlyIndexImpl; +use jujutsu_lib::default_revset_engine::{evaluate, RevsetImpl}; use jujutsu_lib::repo::Repo; -use jujutsu_lib::revset::{Revset, RevsetExpression, RevsetGraphEdge}; +use jujutsu_lib::revset::{RevsetExpression, RevsetGraphEdge}; use test_case::test_case; use testutils::{CommitGraphBuilder, TestRepo}; -fn revset_for_commits<'index>( - repo: &'index dyn Repo, - commits: &[&Commit], -) -> Box + 'index> { - RevsetExpression::commits(commits.iter().map(|commit| commit.id().clone()).collect()) - .evaluate(repo) - .unwrap() +fn revset_for_commits<'index>(repo: &'index dyn Repo, commits: &[&Commit]) -> RevsetImpl<'index> { + let index = repo + .index() + .as_any() + .downcast_ref::() + .unwrap(); + let expression = + RevsetExpression::commits(commits.iter().map(|commit| commit.id().clone()).collect()); + evaluate(repo, index.as_composite(), &expression).unwrap() } fn direct(commit: &Commit) -> RevsetGraphEdge { @@ -66,7 +69,8 @@ fn test_graph_iterator_linearized(skip_transitive_edges: bool) { let root_commit = repo.store().root_commit(); let revset = revset_for_commits(repo.as_ref(), &[&commit_a, &commit_d]); - let commits = RevsetGraphIterator::new(revset.iter()) + let commits = revset + .iter_graph_impl() .set_skip_transitive_edges(skip_transitive_edges) .collect_vec(); assert_eq!(commits.len(), 2); @@ -105,7 +109,8 @@ fn test_graph_iterator_virtual_octopus(skip_transitive_edges: bool) { let root_commit = repo.store().root_commit(); let revset = revset_for_commits(repo.as_ref(), &[&commit_a, &commit_b, &commit_c, &commit_f]); - let commits = RevsetGraphIterator::new(revset.iter()) + let commits = revset + .iter_graph_impl() .set_skip_transitive_edges(skip_transitive_edges) .collect_vec(); assert_eq!(commits.len(), 4); @@ -155,7 +160,8 @@ fn test_graph_iterator_simple_fork(skip_transitive_edges: bool) { let root_commit = repo.store().root_commit(); let revset = revset_for_commits(repo.as_ref(), &[&commit_a, &commit_c, &commit_e]); - let commits = RevsetGraphIterator::new(revset.iter()) + let commits = revset + .iter_graph_impl() .set_skip_transitive_edges(skip_transitive_edges) .collect_vec(); assert_eq!(commits.len(), 3); @@ -195,7 +201,8 @@ fn test_graph_iterator_multiple_missing(skip_transitive_edges: bool) { let root_commit = repo.store().root_commit(); let revset = revset_for_commits(repo.as_ref(), &[&commit_b, &commit_f]); - let commits = RevsetGraphIterator::new(revset.iter()) + let commits = revset + .iter_graph_impl() .set_skip_transitive_edges(skip_transitive_edges) .collect_vec(); assert_eq!(commits.len(), 2); @@ -238,7 +245,8 @@ fn test_graph_iterator_edge_to_ancestor(skip_transitive_edges: bool) { let repo = tx.commit(); let revset = revset_for_commits(repo.as_ref(), &[&commit_c, &commit_d, &commit_f]); - let commits = RevsetGraphIterator::new(revset.iter()) + let commits = revset + .iter_graph_impl() .set_skip_transitive_edges(skip_transitive_edges) .collect_vec(); assert_eq!(commits.len(), 3); @@ -296,7 +304,8 @@ fn test_graph_iterator_edge_escapes_from_(skip_transitive_edges: bool) { repo.as_ref(), &[&commit_a, &commit_d, &commit_g, &commit_h, &commit_j], ); - let commits = RevsetGraphIterator::new(revset.iter()) + let commits = revset + .iter_graph_impl() .set_skip_transitive_edges(skip_transitive_edges) .collect_vec(); assert_eq!(commits.len(), 5);