mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-20 03:20:08 +00:00
cli: add helper method that resolves user symbols in revset expression
revset_util::evaluate() is inlined as there's only one caller.
This commit is contained in:
parent
62e4943c04
commit
b0eb7764d4
2 changed files with 21 additions and 21 deletions
|
@ -847,15 +847,18 @@ fn evaluate_revset_expression<'repo>(
|
|||
span: pest::Span<'_>,
|
||||
expression: &UserRevsetExpression,
|
||||
) -> Result<Box<dyn Revset + 'repo>, TemplateParseError> {
|
||||
let make_error = || TemplateParseError::expression("Failed to evaluate revset", span);
|
||||
let repo = language.repo;
|
||||
let symbol_resolver = revset_util::default_symbol_resolver(
|
||||
language.repo,
|
||||
repo,
|
||||
language.revset_parse_context.symbol_resolvers(),
|
||||
language.id_prefix_context,
|
||||
);
|
||||
let revset =
|
||||
revset_util::evaluate(language.repo, &symbol_resolver, expression).map_err(|err| {
|
||||
TemplateParseError::expression("Failed to evaluate revset", span).with_source(err)
|
||||
})?;
|
||||
let revset = expression
|
||||
.resolve_user_expression(repo, &symbol_resolver)
|
||||
.map_err(|err| make_error().with_source(err))?
|
||||
.evaluate(repo)
|
||||
.map_err(|err| make_error().with_source(err))?;
|
||||
Ok(revset)
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ use jj_lib::id_prefix::IdPrefixContext;
|
|||
use jj_lib::repo::Repo;
|
||||
use jj_lib::revset;
|
||||
use jj_lib::revset::DefaultSymbolResolver;
|
||||
use jj_lib::revset::ResolvedRevsetExpression;
|
||||
use jj_lib::revset::Revset;
|
||||
use jj_lib::revset::RevsetAliasesMap;
|
||||
use jj_lib::revset::RevsetDiagnostics;
|
||||
|
@ -91,14 +92,23 @@ impl<'repo> RevsetExpressionEvaluator<'repo> {
|
|||
self.expression = self.expression.intersection(other);
|
||||
}
|
||||
|
||||
/// Evaluates the expression.
|
||||
pub fn evaluate(&self) -> Result<Box<dyn Revset + 'repo>, UserRevsetEvaluationError> {
|
||||
/// Resolves user symbols in the expression, returns new expression.
|
||||
pub fn resolve(&self) -> Result<Rc<ResolvedRevsetExpression>, RevsetResolutionError> {
|
||||
let symbol_resolver = default_symbol_resolver(
|
||||
self.repo,
|
||||
self.extensions.symbol_resolvers(),
|
||||
self.id_prefix_context,
|
||||
);
|
||||
evaluate(self.repo, &symbol_resolver, &self.expression)
|
||||
self.expression
|
||||
.resolve_user_expression(self.repo, &symbol_resolver)
|
||||
}
|
||||
|
||||
/// Evaluates the expression.
|
||||
pub fn evaluate(&self) -> Result<Box<dyn Revset + 'repo>, UserRevsetEvaluationError> {
|
||||
self.resolve()
|
||||
.map_err(UserRevsetEvaluationError::Resolution)?
|
||||
.evaluate(self.repo)
|
||||
.map_err(UserRevsetEvaluationError::Evaluation)
|
||||
}
|
||||
|
||||
/// Evaluates the expression to an iterator over commit ids. Entries are
|
||||
|
@ -181,19 +191,6 @@ pub fn load_revset_aliases(
|
|||
Ok(aliases_map)
|
||||
}
|
||||
|
||||
pub fn evaluate<'a>(
|
||||
repo: &'a dyn Repo,
|
||||
symbol_resolver: &DefaultSymbolResolver,
|
||||
expression: &UserRevsetExpression,
|
||||
) -> Result<Box<dyn Revset + 'a>, UserRevsetEvaluationError> {
|
||||
let resolved = expression
|
||||
.resolve_user_expression(repo, symbol_resolver)
|
||||
.map_err(UserRevsetEvaluationError::Resolution)?;
|
||||
resolved
|
||||
.evaluate(repo)
|
||||
.map_err(UserRevsetEvaluationError::Evaluation)
|
||||
}
|
||||
|
||||
/// Wraps the given `IdPrefixContext` in `SymbolResolver` to be passed in to
|
||||
/// `evaluate()`.
|
||||
pub fn default_symbol_resolver<'a>(
|
||||
|
|
Loading…
Reference in a new issue