cli: branch: inline make_branch_term(), use singular form

It's used only in transaction descriptions, and I think singular form works
at adjective position.
This commit is contained in:
Yuya Nishihara 2024-06-24 16:34:23 +09:00
parent c240313c4b
commit 19904e9e00
9 changed files with 29 additions and 38 deletions

View File

@ -16,7 +16,6 @@ use clap::builder::NonEmptyStringValueParser;
use jj_lib::object_id::ObjectId as _;
use jj_lib::op_store::RefTarget;
use super::make_branch_term;
use crate::cli_util::{CommandHelper, RevisionArg};
use crate::command_error::{user_error_with_hint, CommandError};
use crate::ui::Ui;
@ -69,9 +68,9 @@ pub fn cmd_branch_create(
tx.finish(
ui,
format!(
"create {} pointing to commit {}",
make_branch_term(branch_names),
target_commit.id().hex()
"create branch {names} pointing to commit {id}",
names = branch_names.join(", "),
id = target_commit.id().hex()
),
)?;
Ok(())

View File

@ -15,7 +15,7 @@
use jj_lib::op_store::RefTarget;
use jj_lib::str_util::StringPattern;
use super::{find_local_branches, make_branch_term};
use super::find_local_branches;
use crate::cli_util::CommandHelper;
use crate::command_error::CommandError;
use crate::ui::Ui;
@ -46,7 +46,7 @@ pub fn cmd_branch_delete(
tx.mut_repo()
.set_local_branch_target(branch_name, RefTarget::absent());
}
tx.finish(ui, format!("delete {}", make_branch_term(&names)))?;
tx.finish(ui, format!("delete branch {}", names.join(", ")))?;
if names.len() > 1 {
writeln!(ui.status(), "Deleted {} branches.", names.len())?;
}

View File

@ -15,7 +15,7 @@
use jj_lib::str_util::StringPattern;
use jj_lib::view::View;
use super::{find_branches_with, make_branch_term};
use super::find_branches_with;
use crate::cli_util::CommandHelper;
use crate::command_error::CommandError;
use crate::ui::Ui;
@ -48,7 +48,7 @@ pub fn cmd_branch_forget(
for branch_name in names.iter() {
tx.mut_repo().remove_branch(branch_name);
}
tx.finish(ui, format!("forget {}", make_branch_term(&names)))?;
tx.finish(ui, format!("forget branch {}", names.join(", ")))?;
if names.len() > 1 {
writeln!(ui.status(), "Forgot {} branches.", names.len())?;
}

View File

@ -22,8 +22,6 @@ mod set;
mod track;
mod untrack;
use std::fmt;
use itertools::Itertools as _;
use jj_lib::backend::CommitId;
use jj_lib::op_store::{RefTarget, RemoteRef};
@ -87,13 +85,6 @@ pub fn cmd_branch(
}
}
fn make_branch_term(branch_names: &[impl fmt::Display]) -> String {
match branch_names {
[branch_name] => format!("branch {}", branch_name),
branch_names => format!("branches {}", branch_names.iter().join(", ")),
}
}
fn find_local_branches(
view: &View,
name_patterns: &[StringPattern],

View File

@ -17,7 +17,7 @@ use jj_lib::object_id::ObjectId as _;
use jj_lib::op_store::RefTarget;
use jj_lib::str_util::StringPattern;
use super::{find_branches_with, is_fast_forward, make_branch_term};
use super::{find_branches_with, is_fast_forward};
use crate::cli_util::{CommandHelper, RevisionArg};
use crate::command_error::{user_error_with_hint, CommandError};
use crate::ui::Ui;
@ -125,9 +125,9 @@ pub fn cmd_branch_move(
tx.finish(
ui,
format!(
"point {} to commit {}",
make_branch_term(&branch_names),
target_commit.id().hex()
"point branch {names} to commit {id}",
names = branch_names.join(", "),
id = target_commit.id().hex()
),
)?;

View File

@ -15,7 +15,6 @@
use jj_lib::op_store::RefTarget;
use jj_lib::str_util::StringPattern;
use super::make_branch_term;
use crate::cli_util::CommandHelper;
use crate::command_error::{user_error, CommandError};
use crate::ui::Ui;
@ -55,14 +54,7 @@ pub fn cmd_branch_rename(
.set_local_branch_target(new_branch, ref_target);
tx.mut_repo()
.set_local_branch_target(old_branch, RefTarget::absent());
tx.finish(
ui,
format!(
"rename {} to {}",
make_branch_term(&[old_branch]),
make_branch_term(&[new_branch]),
),
)?;
tx.finish(ui, format!("rename branch {old_branch} to {new_branch}"))?;
let view = workspace_command.repo().view();
if view

View File

@ -16,7 +16,7 @@ use clap::builder::NonEmptyStringValueParser;
use jj_lib::object_id::ObjectId as _;
use jj_lib::op_store::RefTarget;
use super::{is_fast_forward, make_branch_term};
use super::is_fast_forward;
use crate::cli_util::{CommandHelper, RevisionArg};
use crate::command_error::{user_error_with_hint, CommandError};
use crate::ui::Ui;
@ -77,9 +77,9 @@ pub fn cmd_branch_set(
tx.finish(
ui,
format!(
"point {} to commit {}",
make_branch_term(branch_names),
target_commit.id().hex()
"point branch {names} to commit {id}",
names = branch_names.join(", "),
id = target_commit.id().hex()
),
)?;

View File

@ -14,7 +14,9 @@
use std::collections::HashMap;
use super::{find_remote_branches, make_branch_term};
use itertools::Itertools as _;
use super::find_remote_branches;
use crate::cli_util::{CommandHelper, RemoteBranchNamePattern};
use crate::command_error::CommandError;
use crate::commit_templater::{CommitTemplateLanguage, RefName};
@ -61,7 +63,10 @@ pub fn cmd_branch_track(
tx.mut_repo()
.track_remote_branch(&name.branch, &name.remote);
}
tx.finish(ui, format!("track remote {}", make_branch_term(&names)))?;
tx.finish(
ui,
format!("track remote branch {}", names.iter().join(", ")),
)?;
if names.len() > 1 {
writeln!(
ui.status(),

View File

@ -12,9 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use itertools::Itertools as _;
use jj_lib::git;
use super::{find_remote_branches, make_branch_term};
use super::find_remote_branches;
use crate::cli_util::{CommandHelper, RemoteBranchNamePattern};
use crate::command_error::CommandError;
use crate::ui::Ui;
@ -65,7 +66,10 @@ pub fn cmd_branch_untrack(
tx.mut_repo()
.untrack_remote_branch(&name.branch, &name.remote);
}
tx.finish(ui, format!("untrack remote {}", make_branch_term(&names)))?;
tx.finish(
ui,
format!("untrack remote branch {}", names.iter().join(", ")),
)?;
if names.len() > 1 {
writeln!(
ui.status(),