ok/jj
1
0
Fork 0
forked from mirrors/jj

cli: move make_branch_term out of commands/mod.rs

It is now out of place in mod.rs. It is only used in two places, so
I copied it to each of them.

Follows up on @AntoineCezar 's work.
This commit is contained in:
Ilya Grigoriev 2023-11-17 19:46:22 -08:00
parent af81cbd942
commit 0357915778
3 changed files with 15 additions and 12 deletions

View file

@ -17,7 +17,6 @@ use crate::cli_util::{
parse_string_pattern, user_error, user_error_with_hint, CommandError, CommandHelper,
RevisionArg,
};
use crate::commands::make_branch_term;
use crate::formatter::Formatter;
use crate::ui::Ui;
@ -231,6 +230,13 @@ impl fmt::Display for RemoteBranchNamePattern {
}
}
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(", ")),
}
}
pub fn cmd_branch(
ui: &mut Ui,
command: &CommandHelper,

View file

@ -5,7 +5,7 @@ use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::sync::Mutex;
use std::time::Instant;
use std::{fs, io};
use std::{fmt, fs, io};
use clap::{ArgGroup, Subcommand};
use itertools::Itertools;
@ -33,7 +33,6 @@ use crate::cli_util::{
resolve_multiple_nonempty_revsets, short_change_hash, short_commit_hash, user_error,
user_error_with_hint, CommandError, CommandHelper, RevisionArg, WorkspaceCommandHelper,
};
use crate::commands::make_branch_term;
use crate::progress::Progress;
use crate::ui::Ui;
@ -191,6 +190,13 @@ pub struct GitSubmodulePrintGitmodulesArgs {
revisions: RevisionArg,
}
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 get_git_repo(store: &Store) -> Result<git2::Repository, CommandError> {
match store.backend_impl().downcast_ref::<GitBackend>() {
None => Err(user_error("The repo is not backed by a git repo")),

View file

@ -55,11 +55,9 @@ mod util;
mod version;
mod workspace;
use std::fmt;
use std::fmt::Debug;
use clap::{Command, CommandFactory, FromArgMatches, Subcommand};
use itertools::Itertools;
use tracing::instrument;
use crate::cli_util::{user_error_with_hint, Args, CommandError, CommandHelper};
@ -147,13 +145,6 @@ struct DummyCommandArgs {
_args: Vec<String>,
}
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(", ")),
}
}
pub fn default_app() -> Command {
Commands::augment_subcommands(Args::command())
}