cli: pass CommandHelper reference to WorkspaceCommandHelper constructor

I'll need to access LayeredConfigs there, and I don't think external callers
would want to specify each argument separately.
This commit is contained in:
Yuya Nishihara 2023-05-23 12:15:58 +09:00
parent f1e2849c23
commit 97e2ee2868
2 changed files with 12 additions and 31 deletions

View file

@ -517,15 +517,7 @@ impl CommandHelper {
workspace: Workspace,
repo: Arc<ReadonlyRepo>,
) -> Result<WorkspaceCommandHelper, CommandError> {
WorkspaceCommandHelper::new(
ui,
workspace,
self.cwd.clone(),
self.string_args.clone(),
&self.global_args,
self.settings.clone(),
repo,
)
WorkspaceCommandHelper::new(ui, self, workspace, repo)
}
/// Loads workspace that will diverge from the last working-copy operation.
@ -583,15 +575,12 @@ pub struct WorkspaceCommandHelper {
impl WorkspaceCommandHelper {
pub fn new(
ui: &mut Ui,
command: &CommandHelper,
workspace: Workspace,
cwd: PathBuf,
string_args: Vec<String>,
global_args: &GlobalArgs,
settings: UserSettings,
repo: Arc<ReadonlyRepo>,
) -> Result<Self, CommandError> {
let revset_aliases_map = load_revset_aliases(ui, &settings)?;
let template_aliases_map = load_template_aliases(ui, &settings)?;
let revset_aliases_map = load_revset_aliases(ui, &command.settings)?;
let template_aliases_map = load_template_aliases(ui, &command.settings)?;
// Parse commit_summary template early to report error before starting mutable
// operation.
// TODO: Parsed template can be cached if it doesn't capture repo
@ -601,10 +590,10 @@ impl WorkspaceCommandHelper {
workspace.workspace_id(),
&id_prefix_context,
&template_aliases_map,
&settings,
&command.settings,
)?;
let loaded_at_head = &global_args.at_operation == "@";
let may_update_working_copy = loaded_at_head && !global_args.ignore_working_copy;
let loaded_at_head = command.global_args.at_operation == "@";
let may_update_working_copy = loaded_at_head && !command.global_args.ignore_working_copy;
let mut working_copy_shared_with_git = false;
let maybe_git_backend = repo.store().backend_impl().downcast_ref::<GitBackend>();
if let Some(git_workdir) = maybe_git_backend
@ -614,10 +603,10 @@ impl WorkspaceCommandHelper {
working_copy_shared_with_git = git_workdir == workspace.workspace_root().as_path();
}
Ok(Self {
cwd,
string_args,
global_args: global_args.clone(),
settings,
cwd: command.cwd.clone(),
string_args: command.string_args.clone(),
global_args: command.global_args.clone(),
settings: command.settings.clone(),
workspace,
user_repo: ReadonlyUserRepo::new(repo),
revset_aliases_map,

View file

@ -3346,15 +3346,7 @@ fn cmd_workspace_add(
.display()
)?;
let mut new_workspace_command = WorkspaceCommandHelper::new(
ui,
new_workspace,
command.cwd().to_owned(),
command.string_args().clone(),
command.global_args(),
command.settings().clone(),
repo,
)?;
let mut new_workspace_command = WorkspaceCommandHelper::new(ui, command, new_workspace, repo)?;
let mut tx = new_workspace_command.start_transaction(&format!(
"Create initial working-copy commit in workspace {}",
&name