From f560705a9f1fff5f26c64b0942f50d770e9dea8b Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sat, 6 Apr 2024 18:46:08 +0900 Subject: [PATCH] cli: inline matcher_from_values() in favor of parse_file_patterns() --- cli/src/cli_util.rs | 5 ----- cli/src/commands/commit.rs | 4 +++- cli/src/commands/debug.rs | 4 +++- cli/src/commands/diff.rs | 4 +++- cli/src/commands/files.rs | 4 +++- cli/src/commands/interdiff.rs | 4 +++- cli/src/commands/move.rs | 4 +++- cli/src/commands/resolve.rs | 4 +++- cli/src/commands/restore.rs | 4 +++- cli/src/commands/split.rs | 4 +++- cli/src/commands/squash.rs | 4 +++- cli/src/commands/status.rs | 4 +++- cli/src/commands/untrack.rs | 4 +++- 13 files changed, 36 insertions(+), 17 deletions(-) diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index f0a0c1b4e4..42782313a8 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -671,11 +671,6 @@ impl WorkspaceCommandHelper { } } - pub fn matcher_from_values(&self, values: &[String]) -> Result, CommandError> { - let expr = self.parse_file_patterns(values)?; - Ok(expr.to_matcher()) - } - #[instrument(skip_all)] pub fn base_ignores(&self) -> Result, GitIgnoreError> { fn get_excludes_file_path(config: &gix::config::File) -> Option { diff --git a/cli/src/commands/commit.rs b/cli/src/commands/commit.rs index 2ad459046d..51c41ac6e0 100644 --- a/cli/src/commands/commit.rs +++ b/cli/src/commands/commit.rs @@ -54,7 +54,9 @@ pub(crate) fn cmd_commit( .get_wc_commit_id() .ok_or_else(|| user_error("This command requires a working copy"))?; let commit = workspace_command.repo().store().get_commit(commit_id)?; - let matcher = workspace_command.matcher_from_values(&args.paths)?; + let matcher = workspace_command + .parse_file_patterns(&args.paths)? + .to_matcher(); let diff_selector = workspace_command.diff_selector(ui, args.tool.as_deref(), args.interactive)?; let mut tx = workspace_command.start_transaction(); diff --git a/cli/src/commands/debug.rs b/cli/src/commands/debug.rs index d408e379f6..7916503191 100644 --- a/cli/src/commands/debug.rs +++ b/cli/src/commands/debug.rs @@ -317,7 +317,9 @@ fn cmd_debug_tree( .resolve_single_rev(args.revision.as_ref().unwrap_or(&RevisionArg::AT))?; commit.tree()? }; - let matcher = workspace_command.matcher_from_values(&args.paths)?; + let matcher = workspace_command + .parse_file_patterns(&args.paths)? + .to_matcher(); for (path, value) in tree.entries_matching(matcher.as_ref()) { let ui_path = workspace_command.format_file_path(&path); writeln!(ui.stdout(), "{ui_path}: {value:?}")?; diff --git a/cli/src/commands/diff.rs b/cli/src/commands/diff.rs index 8a589f5c69..99ae066139 100644 --- a/cli/src/commands/diff.rs +++ b/cli/src/commands/diff.rs @@ -76,7 +76,9 @@ pub(crate) fn cmd_diff( from_tree = merge_commit_trees(workspace_command.repo().as_ref(), &parents)?; to_tree = commit.tree()? } - let matcher = workspace_command.matcher_from_values(&args.paths)?; + let matcher = workspace_command + .parse_file_patterns(&args.paths)? + .to_matcher(); let diff_formats = diff_formats_for(command.settings(), &args.format)?; ui.request_pager(); show_diff( diff --git a/cli/src/commands/files.rs b/cli/src/commands/files.rs index d058cf8433..5b836795ae 100644 --- a/cli/src/commands/files.rs +++ b/cli/src/commands/files.rs @@ -40,7 +40,9 @@ pub(crate) fn cmd_files( let workspace_command = command.workspace_helper(ui)?; let commit = workspace_command.resolve_single_rev(&args.revision)?; let tree = commit.tree()?; - let matcher = workspace_command.matcher_from_values(&args.paths)?; + let matcher = workspace_command + .parse_file_patterns(&args.paths)? + .to_matcher(); ui.request_pager(); for (name, _value) in tree.entries_matching(matcher.as_ref()) { writeln!( diff --git a/cli/src/commands/interdiff.rs b/cli/src/commands/interdiff.rs index 09897c05f9..1137656a3f 100644 --- a/cli/src/commands/interdiff.rs +++ b/cli/src/commands/interdiff.rs @@ -55,7 +55,9 @@ pub(crate) fn cmd_interdiff( let from_tree = rebase_to_dest_parent(workspace_command.repo().as_ref(), &from, &to)?; let to_tree = to.tree()?; - let matcher = workspace_command.matcher_from_values(&args.paths)?; + let matcher = workspace_command + .parse_file_patterns(&args.paths)? + .to_matcher(); let diff_formats = diff_util::diff_formats_for(command.settings(), &args.format)?; ui.request_pager(); diff_util::show_diff( diff --git a/cli/src/commands/move.rs b/cli/src/commands/move.rs index c67ad628b0..37c7b822ef 100644 --- a/cli/src/commands/move.rs +++ b/cli/src/commands/move.rs @@ -78,7 +78,9 @@ pub(crate) fn cmd_move( if source.id() == destination.id() { return Err(user_error("Source and destination cannot be the same.")); } - let matcher = workspace_command.matcher_from_values(&args.paths)?; + let matcher = workspace_command + .parse_file_patterns(&args.paths)? + .to_matcher(); let diff_selector = workspace_command.diff_selector(ui, args.tool.as_deref(), args.interactive)?; let mut tx = workspace_command.start_transaction(); diff --git a/cli/src/commands/resolve.rs b/cli/src/commands/resolve.rs index 626f9f5c70..22b5c90a22 100644 --- a/cli/src/commands/resolve.rs +++ b/cli/src/commands/resolve.rs @@ -64,7 +64,9 @@ pub(crate) fn cmd_resolve( args: &ResolveArgs, ) -> Result<(), CommandError> { let mut workspace_command = command.workspace_helper(ui)?; - let matcher = workspace_command.matcher_from_values(&args.paths)?; + let matcher = workspace_command + .parse_file_patterns(&args.paths)? + .to_matcher(); let commit = workspace_command.resolve_single_rev(&args.revision)?; let tree = commit.tree()?; let conflicts = tree diff --git a/cli/src/commands/restore.rs b/cli/src/commands/restore.rs index 49def89df2..abee9a679b 100644 --- a/cli/src/commands/restore.rs +++ b/cli/src/commands/restore.rs @@ -98,7 +98,9 @@ pub(crate) fn cmd_restore( } workspace_command.check_rewritable([to_commit.id()])?; - let matcher = workspace_command.matcher_from_values(&args.paths)?; + let matcher = workspace_command + .parse_file_patterns(&args.paths)? + .to_matcher(); let to_tree = to_commit.tree()?; let new_tree_id = restore_tree(&from_tree, &to_tree, matcher.as_ref())?; if &new_tree_id == to_commit.tree_id() { diff --git a/cli/src/commands/split.rs b/cli/src/commands/split.rs index 7521af558d..0cec68fc2d 100644 --- a/cli/src/commands/split.rs +++ b/cli/src/commands/split.rs @@ -68,7 +68,9 @@ pub(crate) fn cmd_split( let mut workspace_command = command.workspace_helper(ui)?; let commit = workspace_command.resolve_single_rev(&args.revision)?; workspace_command.check_rewritable([commit.id()])?; - let matcher = workspace_command.matcher_from_values(&args.paths)?; + let matcher = workspace_command + .parse_file_patterns(&args.paths)? + .to_matcher(); let diff_selector = workspace_command.diff_selector( ui, args.tool.as_deref(), diff --git a/cli/src/commands/squash.rs b/cli/src/commands/squash.rs index 0141b75dc1..ad5aec0c16 100644 --- a/cli/src/commands/squash.rs +++ b/cli/src/commands/squash.rs @@ -111,7 +111,9 @@ pub(crate) fn cmd_squash( destination = parents.pop().unwrap(); } - let matcher = workspace_command.matcher_from_values(&args.paths)?; + let matcher = workspace_command + .parse_file_patterns(&args.paths)? + .to_matcher(); let diff_selector = workspace_command.diff_selector(ui, args.tool.as_deref(), args.interactive)?; let mut tx = workspace_command.start_transaction(); diff --git a/cli/src/commands/status.rs b/cli/src/commands/status.rs index a446d5176d..6daf7d0ba3 100644 --- a/cli/src/commands/status.rs +++ b/cli/src/commands/status.rs @@ -50,7 +50,9 @@ pub(crate) fn cmd_status( .get_wc_commit_id() .map(|id| repo.store().get_commit(id)) .transpose()?; - let matcher = workspace_command.matcher_from_values(&args.paths)?; + let matcher = workspace_command + .parse_file_patterns(&args.paths)? + .to_matcher(); ui.request_pager(); let mut formatter = ui.stdout_formatter(); let formatter = formatter.as_mut(); diff --git a/cli/src/commands/untrack.rs b/cli/src/commands/untrack.rs index bc637ab072..6fbee3f975 100644 --- a/cli/src/commands/untrack.rs +++ b/cli/src/commands/untrack.rs @@ -44,7 +44,9 @@ pub(crate) fn cmd_untrack( ) -> Result<(), CommandError> { let mut workspace_command = command.workspace_helper(ui)?; let store = workspace_command.repo().store().clone(); - let matcher = workspace_command.matcher_from_values(&args.paths)?; + let matcher = workspace_command + .parse_file_patterns(&args.paths)? + .to_matcher(); let mut tx = workspace_command.start_transaction().into_inner(); let base_ignores = workspace_command.base_ignores()?;