branch.rs: move find_globs function out of cmd_branch_forget

This prepares for using it in `cmd_branch_delete`.
This commit is contained in:
Ilya Grigoriev 2023-06-23 23:27:48 -07:00
parent 144a44914a
commit 97815851f7

View file

@ -201,36 +201,7 @@ fn cmd_branch_set(
Ok(())
}
fn cmd_branch_delete(
ui: &mut Ui,
command: &CommandHelper,
args: &BranchDeleteArgs,
) -> Result<(), CommandError> {
let mut workspace_command = command.workspace_helper(ui)?;
for branch_name in &args.names {
if workspace_command
.repo()
.view()
.get_local_branch(branch_name)
.is_none()
{
return Err(user_error(format!("No such branch: {branch_name}")));
}
}
let mut tx =
workspace_command.start_transaction(&format!("delete {}", make_branch_term(&args.names)));
for branch_name in &args.names {
tx.mut_repo().remove_local_branch(branch_name);
}
tx.finish(ui)?;
Ok(())
}
fn cmd_branch_forget(
ui: &mut Ui,
command: &CommandHelper,
args: &BranchForgetArgs,
) -> Result<(), CommandError> {
/// This function may return the same branch more than once
fn find_globs(view: &View, globs: &[String]) -> Result<Vec<String>, CommandError> {
let mut matching_branches: Vec<String> = vec![];
let mut failed_globs = vec![];
@ -265,6 +236,36 @@ fn cmd_branch_forget(
Ok(matching_branches)
}
fn cmd_branch_delete(
ui: &mut Ui,
command: &CommandHelper,
args: &BranchDeleteArgs,
) -> Result<(), CommandError> {
let mut workspace_command = command.workspace_helper(ui)?;
for branch_name in &args.names {
if workspace_command
.repo()
.view()
.get_local_branch(branch_name)
.is_none()
{
return Err(user_error(format!("No such branch: {branch_name}")));
}
}
let mut tx =
workspace_command.start_transaction(&format!("delete {}", make_branch_term(&args.names)));
for branch_name in &args.names {
tx.mut_repo().remove_local_branch(branch_name);
}
tx.finish(ui)?;
Ok(())
}
fn cmd_branch_forget(
ui: &mut Ui,
command: &CommandHelper,
args: &BranchForgetArgs,
) -> Result<(), CommandError> {
let mut workspace_command = command.workspace_helper(ui)?;
let view = workspace_command.repo().view();
for branch_name in args.names.iter() {