From d635d02f065c11a9b2b0b91e0312155094bd0ba4 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Fri, 21 Oct 2022 13:44:37 +0900 Subject: [PATCH] cli: add WorkspaceCommandHelper::parse_file_path() for convenience WorkspaceCommandHelper knows the context where user file pattern should be resolved. --- src/cli_util.rs | 6 ++++++ src/commands.rs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cli_util.rs b/src/cli_util.rs index a509ce5bb..7d6b14900 100644 --- a/src/cli_util.rs +++ b/src/cli_util.rs @@ -501,6 +501,12 @@ impl WorkspaceCommandHelper { .to_owned() } + /// Parses a path relative to cwd into a RepoPath, which is relative to the + /// workspace root. + pub fn parse_file_path(&self, input: &str) -> Result { + RepoPath::parse_fs_path(&self.cwd, self.workspace_root(), input) + } + pub fn git_config(&self) -> Result { if let Some(git_repo) = self.repo.store().git_repo() { git_repo.config() diff --git a/src/commands.rs b/src/commands.rs index 84146e7a9..75c12fc2a 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1253,7 +1253,7 @@ fn cmd_files(ui: &mut Ui, command: &CommandHelper, args: &FilesArgs) -> Result<( fn cmd_print(ui: &mut Ui, command: &CommandHelper, args: &PrintArgs) -> Result<(), CommandError> { let workspace_command = command.workspace_helper(ui)?; let commit = workspace_command.resolve_single_rev(&args.revision)?; - let path = RepoPath::parse_fs_path(ui.cwd(), workspace_command.workspace_root(), &args.path)?; + let path = workspace_command.parse_file_path(&args.path)?; let repo = workspace_command.repo(); match commit.tree().path_value(&path) { None => {