mirror of
https://github.com/martinvonz/jj.git
synced 2024-11-28 17:41:14 +00:00
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:
parent
144a44914a
commit
97815851f7
1 changed files with 35 additions and 34 deletions
|
@ -201,37 +201,8 @@ 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> {
|
||||
fn find_globs(view: &View, globs: &[String]) -> Result<Vec<String>, 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![];
|
||||
for glob_str in globs {
|
||||
|
@ -263,8 +234,38 @@ 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() {
|
||||
|
|
Loading…
Reference in a new issue