Skip to content

Commit

Permalink
cli: move make_branch_term out of commands/mod.rs
Browse files Browse the repository at this point in the history
It is now out of place in mod.rs. It is only used in two places, so
I copied it in each of them.
  • Loading branch information
ilyagr committed Nov 18, 2023
1 parent af81cbd commit 3b8b193
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
8 changes: 7 additions & 1 deletion cli/src/commands/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down
10 changes: 8 additions & 2 deletions cli/src/commands/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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")),
Expand Down
9 changes: 0 additions & 9 deletions cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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())
}
Expand Down

0 comments on commit 3b8b193

Please sign in to comment.