mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-06 03:22:59 +00:00
index: pass only CompositeIndex to default_revset_engine::evaluate()
This commit is contained in:
parent
cf5cb380bb
commit
b7b9b8c88e
3 changed files with 16 additions and 29 deletions
|
@ -721,8 +721,7 @@ impl Index for MutableIndexImpl {
|
||||||
expression: &ResolvedExpression,
|
expression: &ResolvedExpression,
|
||||||
store: &Arc<Store>,
|
store: &Arc<Store>,
|
||||||
) -> Result<Box<dyn Revset<'index> + 'index>, RevsetEvaluationError> {
|
) -> Result<Box<dyn Revset<'index> + 'index>, RevsetEvaluationError> {
|
||||||
let revset_impl =
|
let revset_impl = default_revset_engine::evaluate(expression, store, CompositeIndex(self))?;
|
||||||
default_revset_engine::evaluate(expression, store, self, CompositeIndex(self))?;
|
|
||||||
Ok(Box::new(revset_impl))
|
Ok(Box::new(revset_impl))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1117,7 +1116,7 @@ impl Index for CompositeIndex<'_> {
|
||||||
expression: &ResolvedExpression,
|
expression: &ResolvedExpression,
|
||||||
store: &Arc<Store>,
|
store: &Arc<Store>,
|
||||||
) -> Result<Box<dyn Revset<'index> + 'index>, RevsetEvaluationError> {
|
) -> 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))
|
Ok(Box::new(revset_impl))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2017,8 +2016,7 @@ impl Index for ReadonlyIndexImpl {
|
||||||
expression: &ResolvedExpression,
|
expression: &ResolvedExpression,
|
||||||
store: &Arc<Store>,
|
store: &Arc<Store>,
|
||||||
) -> Result<Box<dyn Revset<'index> + 'index>, RevsetEvaluationError> {
|
) -> Result<Box<dyn Revset<'index> + 'index>, RevsetEvaluationError> {
|
||||||
let revset_impl =
|
let revset_impl = default_revset_engine::evaluate(expression, store, CompositeIndex(self))?;
|
||||||
default_revset_engine::evaluate(expression, store, self, CompositeIndex(self))?;
|
|
||||||
Ok(Box::new(revset_impl))
|
Ok(Box::new(revset_impl))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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>(
|
pub fn evaluate<'index>(
|
||||||
expression: &ResolvedExpression,
|
expression: &ResolvedExpression,
|
||||||
store: &Arc<Store>,
|
store: &Arc<Store>,
|
||||||
index: &'index dyn Index,
|
index: CompositeIndex<'index>,
|
||||||
composite_index: CompositeIndex<'index>,
|
|
||||||
) -> Result<RevsetImpl<'index>, RevsetEvaluationError> {
|
) -> Result<RevsetImpl<'index>, RevsetEvaluationError> {
|
||||||
let context = EvaluationContext {
|
let context = EvaluationContext {
|
||||||
store: store.clone(),
|
store: store.clone(),
|
||||||
index,
|
index,
|
||||||
composite_index,
|
|
||||||
};
|
};
|
||||||
let internal_revset = context.evaluate(expression)?;
|
let internal_revset = context.evaluate(expression)?;
|
||||||
Ok(RevsetImpl::new(internal_revset, composite_index))
|
Ok(RevsetImpl::new(internal_revset, index))
|
||||||
}
|
}
|
||||||
|
|
||||||
struct EvaluationContext<'index> {
|
struct EvaluationContext<'index> {
|
||||||
store: Arc<Store>,
|
store: Arc<Store>,
|
||||||
index: &'index dyn Index,
|
index: CompositeIndex<'index>,
|
||||||
composite_index: CompositeIndex<'index>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_u32_generation_range(range: &Range<u64>) -> Result<Range<u32>, RevsetEvaluationError> {
|
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 root_ids = root_set.iter().map(|entry| entry.commit_id()).collect_vec();
|
||||||
let head_set = self.evaluate(heads)?;
|
let head_set = self.evaluate(heads)?;
|
||||||
let head_ids = head_set.iter().map(|entry| entry.commit_id()).collect_vec();
|
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 {
|
if generation == &GENERATION_RANGE_FULL {
|
||||||
Ok(Box::new(RevWalkRevset { walk }))
|
Ok(Box::new(RevWalkRevset { walk }))
|
||||||
} else {
|
} else {
|
||||||
|
@ -587,7 +582,7 @@ impl<'index> EvaluationContext<'index> {
|
||||||
.map(|entry| entry.commit_id())
|
.map(|entry| entry.commit_id())
|
||||||
.collect_vec();
|
.collect_vec();
|
||||||
Ok(Box::new(self.revset_for_commit_ids(
|
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) => {
|
ResolvedExpression::Roots(candidates) => {
|
||||||
|
@ -668,7 +663,7 @@ impl<'index> EvaluationContext<'index> {
|
||||||
S: InternalRevset<'a> + ?Sized,
|
S: InternalRevset<'a> + ?Sized,
|
||||||
{
|
{
|
||||||
let head_ids = head_set.iter().map(|entry| entry.commit_id()).collect_vec();
|
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>(
|
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> {
|
fn revset_for_commit_ids(&self, commit_ids: &[CommitId]) -> EagerRevset<'index> {
|
||||||
let mut index_entries = vec![];
|
let mut index_entries = vec![];
|
||||||
for id in commit_ids {
|
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.sort_unstable_by_key(|b| Reverse(b.position()));
|
||||||
index_entries.dedup();
|
index_entries.dedup();
|
||||||
|
@ -809,7 +804,7 @@ fn pure_predicate_fn<'index>(
|
||||||
|
|
||||||
fn build_predicate_fn<'index>(
|
fn build_predicate_fn<'index>(
|
||||||
store: Arc<Store>,
|
store: Arc<Store>,
|
||||||
index: &'index dyn Index,
|
index: CompositeIndex<'index>,
|
||||||
predicate: &RevsetFilterPredicate,
|
predicate: &RevsetFilterPredicate,
|
||||||
) -> Box<dyn ToPredicateFn + 'index> {
|
) -> Box<dyn ToPredicateFn + 'index> {
|
||||||
match predicate {
|
match predicate {
|
||||||
|
@ -866,7 +861,7 @@ fn build_predicate_fn<'index>(
|
||||||
|
|
||||||
fn has_diff_from_parent(
|
fn has_diff_from_parent(
|
||||||
store: &Arc<Store>,
|
store: &Arc<Store>,
|
||||||
index: &dyn Index,
|
index: CompositeIndex<'_>,
|
||||||
entry: &IndexEntry<'_>,
|
entry: &IndexEntry<'_>,
|
||||||
matcher: &dyn Matcher,
|
matcher: &dyn Matcher,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
|
@ -881,7 +876,7 @@ fn has_diff_from_parent(
|
||||||
return false;
|
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();
|
let to_tree = commit.tree();
|
||||||
from_tree.diff(&to_tree, matcher).next().is_some()
|
from_tree.diff(&to_tree, matcher).next().is_some()
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@ use itertools::Itertools;
|
||||||
use jujutsu_lib::commit::Commit;
|
use jujutsu_lib::commit::Commit;
|
||||||
use jujutsu_lib::default_index_store::ReadonlyIndexWrapper;
|
use jujutsu_lib::default_index_store::ReadonlyIndexWrapper;
|
||||||
use jujutsu_lib::default_revset_engine::{evaluate, RevsetImpl};
|
use jujutsu_lib::default_revset_engine::{evaluate, RevsetImpl};
|
||||||
use jujutsu_lib::index::ReadonlyIndex as _;
|
|
||||||
use jujutsu_lib::repo::{ReadonlyRepo, Repo as _};
|
use jujutsu_lib::repo::{ReadonlyRepo, Repo as _};
|
||||||
use jujutsu_lib::revset::{ResolvedExpression, RevsetGraphEdge};
|
use jujutsu_lib::revset::{ResolvedExpression, RevsetGraphEdge};
|
||||||
use test_case::test_case;
|
use test_case::test_case;
|
||||||
|
@ -30,16 +29,11 @@ fn revset_for_commits<'index>(
|
||||||
.readonly_index()
|
.readonly_index()
|
||||||
.as_any()
|
.as_any()
|
||||||
.downcast_ref::<ReadonlyIndexWrapper>()
|
.downcast_ref::<ReadonlyIndexWrapper>()
|
||||||
.unwrap();
|
.unwrap()
|
||||||
|
.as_composite();
|
||||||
let expression =
|
let expression =
|
||||||
ResolvedExpression::Commits(commits.iter().map(|commit| commit.id().clone()).collect());
|
ResolvedExpression::Commits(commits.iter().map(|commit| commit.id().clone()).collect());
|
||||||
evaluate(
|
evaluate(&expression, repo.store(), index).unwrap()
|
||||||
&expression,
|
|
||||||
repo.store(),
|
|
||||||
index.as_index(),
|
|
||||||
index.as_composite(),
|
|
||||||
)
|
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn direct(commit: &Commit) -> RevsetGraphEdge {
|
fn direct(commit: &Commit) -> RevsetGraphEdge {
|
||||||
|
|
Loading…
Reference in a new issue