index: unify evaluate_revset() implementations

The lifetime is a bit tricky since CompositeIndex is a reference wrapper
whereas Index trait has no notion about ownership.
This commit is contained in:
Yuya Nishihara 2023-05-26 17:06:55 +09:00
parent b7b9b8c88e
commit f27ac22ba4

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, CompositeIndex(self))?;
Ok(Box::new(revset_impl))
CompositeIndex(self).evaluate_revset(expression, store)
}
}
@ -1039,6 +1038,15 @@ impl<'a> CompositeIndex<'a> {
}
candidate_positions
}
fn evaluate_revset(
&self,
expression: &ResolvedExpression,
store: &Arc<Store>,
) -> Result<Box<dyn Revset<'a> + 'a>, RevsetEvaluationError> {
let revset_impl = default_revset_engine::evaluate(expression, store, *self)?;
Ok(Box::new(revset_impl))
}
}
impl Index for CompositeIndex<'_> {
@ -1116,8 +1124,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)?;
Ok(Box::new(revset_impl))
CompositeIndex::evaluate_revset(self, expression, store)
}
}
@ -2016,8 +2023,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, CompositeIndex(self))?;
Ok(Box::new(revset_impl))
CompositeIndex(self).evaluate_revset(expression, store)
}
}