From 1e3b49abf54e4d9128a8d2ced93f0aba4d45c54a Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sun, 26 May 2024 05:33:54 -0700 Subject: [PATCH] revset: use `FsRepoPathUiConverter` in `RevsetWorkspaceContext` --- cli/src/cli_util.rs | 3 +-- lib/src/revset.rs | 19 +++++++++---------- lib/tests/test_revset.rs | 9 ++++++--- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index 4761ff4ea..19a340815 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -994,9 +994,8 @@ impl WorkspaceCommandHelper { pub(crate) fn revset_parse_context(&self) -> RevsetParseContext { let workspace_context = RevsetWorkspaceContext { - cwd: &self.cwd, + path_converter: &self.path_converter, workspace_id: self.workspace_id(), - workspace_root: self.workspace.workspace_root(), }; RevsetParseContext::new( &self.revset_aliases_map, diff --git a/lib/src/revset.rs b/lib/src/revset.rs index d092159f6..50c82a29b 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -18,7 +18,6 @@ use std::any::Any; use std::collections::{hash_map, HashMap}; use std::convert::Infallible; use std::ops::Range; -use std::path::Path; use std::rc::Rc; use std::str::FromStr; use std::sync::Arc; @@ -783,14 +782,10 @@ static BUILTIN_FUNCTION_MAP: Lazy> = Lazy: map.insert("file", |name, arguments_pair, state| { let arguments_span = arguments_pair.as_span(); if let Some(ctx) = state.workspace_ctx { - let path_converter = RepoPathUiConverter::Fs { - cwd: ctx.cwd.to_owned(), - base: ctx.workspace_root.to_owned(), - }; let file_expressions: Vec<_> = arguments_pair .into_inner() .map(|arg| { - parse_function_argument_to_file_pattern(name, arg, state, &path_converter) + parse_function_argument_to_file_pattern(name, arg, state, ctx.path_converter) }) .map_ok(FilesetExpression::pattern) .try_collect()?; @@ -2060,13 +2055,14 @@ impl<'a> RevsetParseContext<'a> { /// Workspace information needed to parse revset expression. #[derive(Clone, Debug)] pub struct RevsetWorkspaceContext<'a> { - pub cwd: &'a Path, + pub path_converter: &'a RepoPathUiConverter, pub workspace_id: &'a WorkspaceId, - pub workspace_root: &'a Path, } #[cfg(test)] mod tests { + use std::path::PathBuf; + use assert_matches::assert_matches; use super::*; @@ -2108,10 +2104,13 @@ mod tests { workspace_id: &WorkspaceId, ) -> Result, RevsetParseErrorKind> { // Set up pseudo context to resolve `workspace_id@` and `file(path)` + let path_converter = RepoPathUiConverter::Fs { + cwd: PathBuf::from("/"), + base: PathBuf::from("/"), + }; let workspace_ctx = RevsetWorkspaceContext { - cwd: Path::new("/"), + path_converter: &path_converter, workspace_id, - workspace_root: Path::new("/"), }; let mut aliases_map = RevsetAliasesMap::new(); for (decl, defn) in aliases { diff --git a/lib/tests/test_revset.rs b/lib/tests/test_revset.rs index dcefc44cb..53be2381f 100644 --- a/lib/tests/test_revset.rs +++ b/lib/tests/test_revset.rs @@ -24,7 +24,7 @@ use jj_lib::git_backend::GitBackend; use jj_lib::object_id::ObjectId; use jj_lib::op_store::{RefTarget, RemoteRef, RemoteRefState, WorkspaceId}; use jj_lib::repo::Repo; -use jj_lib::repo_path::RepoPath; +use jj_lib::repo_path::{RepoPath, RepoPathUiConverter}; use jj_lib::revset::{ optimize, parse, DefaultSymbolResolver, FailingSymbolResolver, ResolvedExpression, Revset, RevsetAliasesMap, RevsetExpression, RevsetExtensions, RevsetFilterPredicate, @@ -855,10 +855,13 @@ fn resolve_commit_ids_in_workspace( cwd: Option<&Path>, ) -> Vec { let settings = testutils::user_settings(); + let path_converter = RepoPathUiConverter::Fs { + cwd: cwd.unwrap_or_else(|| workspace.workspace_root()).to_owned(), + base: workspace.workspace_root().to_owned(), + }; let workspace_ctx = RevsetWorkspaceContext { - cwd: cwd.unwrap_or_else(|| workspace.workspace_root()), + path_converter: &path_converter, workspace_id: workspace.workspace_id(), - workspace_root: workspace.workspace_root(), }; let aliases_map = RevsetAliasesMap::default(); let extensions = RevsetExtensions::default();