Skip to content

Commit

Permalink
cli: inline matcher_from_values() in favor of parse_file_patterns()
Browse files Browse the repository at this point in the history
  • Loading branch information
yuja committed Apr 6, 2024
1 parent 8df979c commit f560705
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 17 deletions.
5 changes: 0 additions & 5 deletions cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,11 +671,6 @@ impl WorkspaceCommandHelper {
}
}

pub fn matcher_from_values(&self, values: &[String]) -> Result<Box<dyn Matcher>, CommandError> {
let expr = self.parse_file_patterns(values)?;
Ok(expr.to_matcher())
}

#[instrument(skip_all)]
pub fn base_ignores(&self) -> Result<Arc<GitIgnoreFile>, GitIgnoreError> {
fn get_excludes_file_path(config: &gix::config::File) -> Option<PathBuf> {
Expand Down
4 changes: 3 additions & 1 deletion cli/src/commands/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion cli/src/commands/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}")?;
Expand Down
4 changes: 3 additions & 1 deletion cli/src/commands/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion cli/src/commands/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
4 changes: 3 additions & 1 deletion cli/src/commands/interdiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion cli/src/commands/move.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion cli/src/commands/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion cli/src/commands/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 3 additions & 1 deletion cli/src/commands/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 3 additions & 1 deletion cli/src/commands/squash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion cli/src/commands/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion cli/src/commands/untrack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand Down

0 comments on commit f560705

Please sign in to comment.