mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-08 21:55:47 +00:00
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:
parent
f1e2849c23
commit
97e2ee2868
2 changed files with 12 additions and 31 deletions
|
@ -517,15 +517,7 @@ impl CommandHelper {
|
||||||
workspace: Workspace,
|
workspace: Workspace,
|
||||||
repo: Arc<ReadonlyRepo>,
|
repo: Arc<ReadonlyRepo>,
|
||||||
) -> Result<WorkspaceCommandHelper, CommandError> {
|
) -> Result<WorkspaceCommandHelper, CommandError> {
|
||||||
WorkspaceCommandHelper::new(
|
WorkspaceCommandHelper::new(ui, self, workspace, repo)
|
||||||
ui,
|
|
||||||
workspace,
|
|
||||||
self.cwd.clone(),
|
|
||||||
self.string_args.clone(),
|
|
||||||
&self.global_args,
|
|
||||||
self.settings.clone(),
|
|
||||||
repo,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Loads workspace that will diverge from the last working-copy operation.
|
/// Loads workspace that will diverge from the last working-copy operation.
|
||||||
|
@ -583,15 +575,12 @@ pub struct WorkspaceCommandHelper {
|
||||||
impl WorkspaceCommandHelper {
|
impl WorkspaceCommandHelper {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
ui: &mut Ui,
|
ui: &mut Ui,
|
||||||
|
command: &CommandHelper,
|
||||||
workspace: Workspace,
|
workspace: Workspace,
|
||||||
cwd: PathBuf,
|
|
||||||
string_args: Vec<String>,
|
|
||||||
global_args: &GlobalArgs,
|
|
||||||
settings: UserSettings,
|
|
||||||
repo: Arc<ReadonlyRepo>,
|
repo: Arc<ReadonlyRepo>,
|
||||||
) -> Result<Self, CommandError> {
|
) -> Result<Self, CommandError> {
|
||||||
let revset_aliases_map = load_revset_aliases(ui, &settings)?;
|
let revset_aliases_map = load_revset_aliases(ui, &command.settings)?;
|
||||||
let template_aliases_map = load_template_aliases(ui, &settings)?;
|
let template_aliases_map = load_template_aliases(ui, &command.settings)?;
|
||||||
// Parse commit_summary template early to report error before starting mutable
|
// Parse commit_summary template early to report error before starting mutable
|
||||||
// operation.
|
// operation.
|
||||||
// TODO: Parsed template can be cached if it doesn't capture repo
|
// TODO: Parsed template can be cached if it doesn't capture repo
|
||||||
|
@ -601,10 +590,10 @@ impl WorkspaceCommandHelper {
|
||||||
workspace.workspace_id(),
|
workspace.workspace_id(),
|
||||||
&id_prefix_context,
|
&id_prefix_context,
|
||||||
&template_aliases_map,
|
&template_aliases_map,
|
||||||
&settings,
|
&command.settings,
|
||||||
)?;
|
)?;
|
||||||
let loaded_at_head = &global_args.at_operation == "@";
|
let loaded_at_head = command.global_args.at_operation == "@";
|
||||||
let may_update_working_copy = loaded_at_head && !global_args.ignore_working_copy;
|
let may_update_working_copy = loaded_at_head && !command.global_args.ignore_working_copy;
|
||||||
let mut working_copy_shared_with_git = false;
|
let mut working_copy_shared_with_git = false;
|
||||||
let maybe_git_backend = repo.store().backend_impl().downcast_ref::<GitBackend>();
|
let maybe_git_backend = repo.store().backend_impl().downcast_ref::<GitBackend>();
|
||||||
if let Some(git_workdir) = maybe_git_backend
|
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();
|
working_copy_shared_with_git = git_workdir == workspace.workspace_root().as_path();
|
||||||
}
|
}
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
cwd,
|
cwd: command.cwd.clone(),
|
||||||
string_args,
|
string_args: command.string_args.clone(),
|
||||||
global_args: global_args.clone(),
|
global_args: command.global_args.clone(),
|
||||||
settings,
|
settings: command.settings.clone(),
|
||||||
workspace,
|
workspace,
|
||||||
user_repo: ReadonlyUserRepo::new(repo),
|
user_repo: ReadonlyUserRepo::new(repo),
|
||||||
revset_aliases_map,
|
revset_aliases_map,
|
||||||
|
|
|
@ -3346,15 +3346,7 @@ fn cmd_workspace_add(
|
||||||
.display()
|
.display()
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let mut new_workspace_command = WorkspaceCommandHelper::new(
|
let mut new_workspace_command = WorkspaceCommandHelper::new(ui, command, new_workspace, repo)?;
|
||||||
ui,
|
|
||||||
new_workspace,
|
|
||||||
command.cwd().to_owned(),
|
|
||||||
command.string_args().clone(),
|
|
||||||
command.global_args(),
|
|
||||||
command.settings().clone(),
|
|
||||||
repo,
|
|
||||||
)?;
|
|
||||||
let mut tx = new_workspace_command.start_transaction(&format!(
|
let mut tx = new_workspace_command.start_transaction(&format!(
|
||||||
"Create initial working-copy commit in workspace {}",
|
"Create initial working-copy commit in workspace {}",
|
||||||
&name
|
&name
|
||||||
|
|
Loading…
Reference in a new issue