diff --git a/cli/src/commit_templater.rs b/cli/src/commit_templater.rs index bb5adcebb..e939485c6 100644 --- a/cli/src/commit_templater.rs +++ b/cli/src/commit_templater.rs @@ -847,15 +847,18 @@ fn evaluate_revset_expression<'repo>( span: pest::Span<'_>, expression: &UserRevsetExpression, ) -> Result, 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) } diff --git a/cli/src/revset_util.rs b/cli/src/revset_util.rs index e1b42715f..7ec6c9b1e 100644 --- a/cli/src/revset_util.rs +++ b/cli/src/revset_util.rs @@ -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, UserRevsetEvaluationError> { + /// Resolves user symbols in the expression, returns new expression. + pub fn resolve(&self) -> Result, 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, 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, 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>(