Skip to content

Commit

Permalink
cli: branch: inline make_branch_term(), simply use plural form
Browse files Browse the repository at this point in the history
It's used only in transaction descriptions, and I don't think singular/plural
form matters here.
  • Loading branch information
yuja committed Jun 26, 2024
1 parent d035d0b commit 0f14ea8
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 38 deletions.
7 changes: 3 additions & 4 deletions cli/src/commands/branch/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 branches {names} pointing to commit {id}",
names = branch_names.join(", "),
id = target_commit.id().hex()
),
)?;
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions cli/src/commands/branch/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 branches {}", names.join(", ")))?;
writeln!(ui.status(), "Deleted {} branches.", names.len())?;
Ok(())
}
4 changes: 2 additions & 2 deletions cli/src/commands/branch/forget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 branches {}", names.join(", ")))?;
writeln!(ui.status(), "Forgot {} branches.", names.len())?;
Ok(())
}
Expand Down
9 changes: 0 additions & 9 deletions cli/src/commands/branch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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],
Expand Down
8 changes: 4 additions & 4 deletions cli/src/commands/branch/move.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 branches {names} to commit {id}",
names = branch_names.join(", "),
id = target_commit.id().hex()
),
)?;

Expand Down
10 changes: 1 addition & 9 deletions cli/src/commands/branch/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions cli/src/commands/branch/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 branches {names} to commit {id}",
names = branch_names.join(", "),
id = target_commit.id().hex()
),
)?;

Expand Down
9 changes: 7 additions & 2 deletions cli/src/commands/branch/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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 branches {}", names.iter().join(", ")),
)?;
if !names.is_empty() {
writeln!(
ui.status(),
Expand Down
8 changes: 6 additions & 2 deletions cli/src/commands/branch/untrack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 branches {}", names.iter().join(", ")),
)?;
if !names.is_empty() {
writeln!(
ui.status(),
Expand Down

0 comments on commit 0f14ea8

Please sign in to comment.