Skip to content

Commit

Permalink
cli: make WorkspaceCommandHelper create SymbolResolver
Browse files Browse the repository at this point in the history
I would eventually want the `SymbolResolver` to be customizable (in
custom `jj` binaries), so we want to make sure we always use the
customized version of it.

I left `RevsetExpression::resolve()` unchanged. I consider that to be
for programmatically created expressions.
  • Loading branch information
martinvonz committed May 12, 2023
1 parent 5e7c57c commit 99e9cd7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
7 changes: 3 additions & 4 deletions lib/src/revset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,13 +441,12 @@ impl RevsetExpression {
.map(|expression| resolve_visibility(repo, &expression))
}

pub fn resolve_in_workspace(
pub fn resolve_user_expression(
self: Rc<Self>,
repo: &dyn Repo,
workspace_ctx: &RevsetWorkspaceContext,
symbol_resolver: &dyn SymbolResolver,
) -> Result<ResolvedExpression, RevsetResolutionError> {
let symbol_resolver = DefaultSymbolResolver::new(repo, Some(workspace_ctx.workspace_id));
resolve_symbols(repo, self, &symbol_resolver)
resolve_symbols(repo, self, symbol_resolver)
.map(|expression| resolve_visibility(repo, &expression))
}
}
Expand Down
9 changes: 5 additions & 4 deletions lib/tests/test_revset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ use jujutsu_lib::op_store::{RefTarget, WorkspaceId};
use jujutsu_lib::repo::Repo;
use jujutsu_lib::repo_path::RepoPath;
use jujutsu_lib::revset::{
optimize, parse, resolve_symbol, ReverseRevsetGraphIterator, Revset, RevsetAliasesMap,
RevsetExpression, RevsetFilterPredicate, RevsetGraphEdge, RevsetResolutionError,
RevsetWorkspaceContext,
optimize, parse, resolve_symbol, DefaultSymbolResolver, ReverseRevsetGraphIterator, Revset,
RevsetAliasesMap, RevsetExpression, RevsetFilterPredicate, RevsetGraphEdge,
RevsetResolutionError, RevsetWorkspaceContext,
};
use jujutsu_lib::settings::GitSettings;
use jujutsu_lib::tree::merge_trees;
Expand Down Expand Up @@ -521,8 +521,9 @@ fn resolve_commit_ids_in_workspace(
};
let expression =
optimize(parse(revset_str, &RevsetAliasesMap::new(), Some(&workspace_ctx)).unwrap());
let symbol_resolver = DefaultSymbolResolver::new(repo, Some(workspace_ctx.workspace_id));
let expression = expression
.resolve_in_workspace(repo, &workspace_ctx)
.resolve_user_expression(repo, &symbol_resolver)
.unwrap();
expression.evaluate(repo).unwrap().iter().collect()
}
Expand Down
13 changes: 9 additions & 4 deletions src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ use jujutsu_lib::repo::{
};
use jujutsu_lib::repo_path::{FsPathParseError, RepoPath};
use jujutsu_lib::revset::{
Revset, RevsetAliasesMap, RevsetEvaluationError, RevsetExpression, RevsetIteratorExt,
RevsetParseError, RevsetParseErrorKind, RevsetResolutionError, RevsetWorkspaceContext,
DefaultSymbolResolver, Revset, RevsetAliasesMap, RevsetEvaluationError, RevsetExpression,
RevsetIteratorExt, RevsetParseError, RevsetParseErrorKind, RevsetResolutionError,
RevsetWorkspaceContext,
};
use jujutsu_lib::settings::UserSettings;
use jujutsu_lib::transaction::Transaction;
Expand Down Expand Up @@ -883,8 +884,8 @@ impl WorkspaceCommandHelper {
&'repo self,
revset_expression: Rc<RevsetExpression>,
) -> Result<Box<dyn Revset<'repo> + 'repo>, CommandError> {
let revset_expression =
revset_expression.resolve_in_workspace(self.repo.as_ref(), &self.revset_context())?;
let revset_expression = revset_expression
.resolve_user_expression(self.repo.as_ref(), &self.revset_symbol_resolver())?;
Ok(revset_expression.evaluate(self.repo.as_ref())?)
}

Expand All @@ -900,6 +901,10 @@ impl WorkspaceCommandHelper {
}
}

pub(crate) fn revset_symbol_resolver(&self) -> DefaultSymbolResolver<'_> {
DefaultSymbolResolver::new(self.repo().as_ref(), Some(self.workspace_id()))
}

pub fn template_aliases_map(&self) -> &TemplateAliasesMap {
&self.template_aliases_map
}
Expand Down
3 changes: 2 additions & 1 deletion src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3224,7 +3224,8 @@ fn cmd_debug_revset(
writeln!(ui, "{expression:#?}")?;
writeln!(ui)?;

let expression = expression.resolve_in_workspace(repo, &workspace_ctx)?;
let expression =
expression.resolve_user_expression(repo, &workspace_command.revset_symbol_resolver())?;
writeln!(ui, "-- Resolved:")?;
writeln!(ui, "{expression:#?}")?;
writeln!(ui)?;
Expand Down

0 comments on commit 99e9cd7

Please sign in to comment.