index: pass only CompositeIndex to default_revset_engine::evaluate()

This commit is contained in:
Yuya Nishihara 2023-05-26 16:36:47 +09:00
parent cf5cb380bb
commit b7b9b8c88e
3 changed files with 16 additions and 29 deletions

View file

@ -721,8 +721,7 @@ impl Index for MutableIndexImpl {
expression: &ResolvedExpression,
store: &Arc<Store>,
) -> Result<Box<dyn Revset<'index> + 'index>, RevsetEvaluationError> {
let revset_impl =
default_revset_engine::evaluate(expression, store, self, CompositeIndex(self))?;
let revset_impl = default_revset_engine::evaluate(expression, store, CompositeIndex(self))?;
Ok(Box::new(revset_impl))
}
}
@ -1117,7 +1116,7 @@ impl Index for CompositeIndex<'_> {
expression: &ResolvedExpression,
store: &Arc<Store>,
) -> Result<Box<dyn Revset<'index> + 'index>, RevsetEvaluationError> {
let revset_impl = default_revset_engine::evaluate(expression, store, self, *self)?;
let revset_impl = default_revset_engine::evaluate(expression, store, *self)?;
Ok(Box::new(revset_impl))
}
}
@ -2017,8 +2016,7 @@ impl Index for ReadonlyIndexImpl {
expression: &ResolvedExpression,
store: &Arc<Store>,
) -> Result<Box<dyn Revset<'index> + 'index>, RevsetEvaluationError> {
let revset_impl =
default_revset_engine::evaluate(expression, store, self, CompositeIndex(self))?;
let revset_impl = default_revset_engine::evaluate(expression, store, CompositeIndex(self))?;
Ok(Box::new(revset_impl))
}
}

View file

@ -481,27 +481,22 @@ impl<'index, I1: Iterator<Item = IndexEntry<'index>>, I2: Iterator<Item = IndexE
}
}
// TODO: Having to pass both `&dyn Index` and `CompositeIndex` is a bit ugly.
// Maybe we should make `CompositeIndex` implement `Index`?
pub fn evaluate<'index>(
expression: &ResolvedExpression,
store: &Arc<Store>,
index: &'index dyn Index,
composite_index: CompositeIndex<'index>,
index: CompositeIndex<'index>,
) -> Result<RevsetImpl<'index>, RevsetEvaluationError> {
let context = EvaluationContext {
store: store.clone(),
index,
composite_index,
};
let internal_revset = context.evaluate(expression)?;
Ok(RevsetImpl::new(internal_revset, composite_index))
Ok(RevsetImpl::new(internal_revset, index))
}
struct EvaluationContext<'index> {
store: Arc<Store>,
index: &'index dyn Index,
composite_index: CompositeIndex<'index>,
index: CompositeIndex<'index>,
}
fn to_u32_generation_range(range: &Range<u64>) -> Result<Range<u32>, RevsetEvaluationError> {
@ -543,7 +538,7 @@ impl<'index> EvaluationContext<'index> {
let root_ids = root_set.iter().map(|entry| entry.commit_id()).collect_vec();
let head_set = self.evaluate(heads)?;
let head_ids = head_set.iter().map(|entry| entry.commit_id()).collect_vec();
let walk = self.composite_index.walk_revs(&head_ids, &root_ids);
let walk = self.index.walk_revs(&head_ids, &root_ids);
if generation == &GENERATION_RANGE_FULL {
Ok(Box::new(RevWalkRevset { walk }))
} else {
@ -587,7 +582,7 @@ impl<'index> EvaluationContext<'index> {
.map(|entry| entry.commit_id())
.collect_vec();
Ok(Box::new(self.revset_for_commit_ids(
&self.composite_index.heads(&mut candidate_ids.iter()),
&self.index.heads(&mut candidate_ids.iter()),
)))
}
ResolvedExpression::Roots(candidates) => {
@ -668,7 +663,7 @@ impl<'index> EvaluationContext<'index> {
S: InternalRevset<'a> + ?Sized,
{
let head_ids = head_set.iter().map(|entry| entry.commit_id()).collect_vec();
self.composite_index.walk_revs(&head_ids, &[])
self.index.walk_revs(&head_ids, &[])
}
fn walk_children<'a, 'b, S, T>(
@ -735,7 +730,7 @@ impl<'index> EvaluationContext<'index> {
fn revset_for_commit_ids(&self, commit_ids: &[CommitId]) -> EagerRevset<'index> {
let mut index_entries = vec![];
for id in commit_ids {
index_entries.push(self.composite_index.entry_by_id(id).unwrap());
index_entries.push(self.index.entry_by_id(id).unwrap());
}
index_entries.sort_unstable_by_key(|b| Reverse(b.position()));
index_entries.dedup();
@ -809,7 +804,7 @@ fn pure_predicate_fn<'index>(
fn build_predicate_fn<'index>(
store: Arc<Store>,
index: &'index dyn Index,
index: CompositeIndex<'index>,
predicate: &RevsetFilterPredicate,
) -> Box<dyn ToPredicateFn + 'index> {
match predicate {
@ -866,7 +861,7 @@ fn build_predicate_fn<'index>(
fn has_diff_from_parent(
store: &Arc<Store>,
index: &dyn Index,
index: CompositeIndex<'_>,
entry: &IndexEntry<'_>,
matcher: &dyn Matcher,
) -> bool {
@ -881,7 +876,7 @@ fn has_diff_from_parent(
return false;
}
}
let from_tree = rewrite::merge_commit_trees_without_repo(store, index, &parents);
let from_tree = rewrite::merge_commit_trees_without_repo(store, &index, &parents);
let to_tree = commit.tree();
from_tree.diff(&to_tree, matcher).next().is_some()
}

View file

@ -16,7 +16,6 @@ use itertools::Itertools;
use jujutsu_lib::commit::Commit;
use jujutsu_lib::default_index_store::ReadonlyIndexWrapper;
use jujutsu_lib::default_revset_engine::{evaluate, RevsetImpl};
use jujutsu_lib::index::ReadonlyIndex as _;
use jujutsu_lib::repo::{ReadonlyRepo, Repo as _};
use jujutsu_lib::revset::{ResolvedExpression, RevsetGraphEdge};
use test_case::test_case;
@ -30,16 +29,11 @@ fn revset_for_commits<'index>(
.readonly_index()
.as_any()
.downcast_ref::<ReadonlyIndexWrapper>()
.unwrap();
.unwrap()
.as_composite();
let expression =
ResolvedExpression::Commits(commits.iter().map(|commit| commit.id().clone()).collect());
evaluate(
&expression,
repo.store(),
index.as_index(),
index.as_composite(),
)
.unwrap()
evaluate(&expression, repo.store(), index).unwrap()
}
fn direct(commit: &Commit) -> RevsetGraphEdge {