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

cli: move call to snapshot() out of for_loaded_repo()

We don't always want to do the snapshotting etc. right away, so let's
have the callers decide when to do it. This is just a refactoring;
I'll change the behavior slightly in separate commits.
This commit is contained in:
Martin von Zweigbergk 2022-10-07 23:20:00 -07:00 committed by Martin von Zweigbergk
parent 94a91d9864
commit 34c24ae035
2 changed files with 9 additions and 6 deletions

View file

@ -247,6 +247,7 @@ jj init --git-repo=.";
let base_repo = repo_loader.load_at(&op_heads[0]);
// TODO: It may be helpful to print each operation we're merging here
let mut workspace_command = self.for_loaded_repo(ui, workspace, base_repo)?;
workspace_command.snapshot(ui)?;
let mut tx = workspace_command.start_transaction("resolve concurrent operations");
for other_op_head in op_heads.into_iter().skip(1) {
tx.merge_operation(other_op_head);
@ -266,24 +267,24 @@ jj init --git-repo=.";
return Ok(workspace_command);
}
};
self.for_loaded_repo(ui, workspace, repo)
let mut workspace_command = self.for_loaded_repo(ui, workspace, repo)?;
workspace_command.snapshot(ui)?;
Ok(workspace_command)
}
pub fn for_loaded_repo(
&self,
ui: &mut Ui,
ui: &Ui,
workspace: Workspace,
repo: Arc<ReadonlyRepo>,
) -> Result<WorkspaceCommandHelper, CommandError> {
let mut helper = WorkspaceCommandHelper::new(
WorkspaceCommandHelper::new(
ui,
workspace,
self.string_args.clone(),
&self.global_args,
repo,
)?;
helper.snapshot(ui)?;
Ok(helper)
)
}
}

View file

@ -1077,6 +1077,7 @@ fn cmd_init(ui: &mut Ui, command: &CommandHelper, args: &InitArgs) -> Result<(),
Workspace::init_external_git(ui.settings(), &wc_path, &git_store_path)?;
let git_repo = repo.store().git_repo().unwrap();
let mut workspace_command = command.for_loaded_repo(ui, workspace, repo)?;
workspace_command.snapshot(ui)?;
if workspace_command.working_copy_shared_with_git() {
add_to_git_exclude(ui, &git_repo)?;
} else {
@ -4105,6 +4106,7 @@ fn do_git_clone(
let git_repo = get_git_repo(repo.store())?;
writeln!(ui, r#"Fetching into new repo in "{}""#, wc_path.display())?;
let mut workspace_command = command.for_loaded_repo(ui, workspace, repo)?;
workspace_command.snapshot(ui)?;
let remote_name = "origin";
git_repo.remote(remote_name, source).unwrap();
let mut fetch_tx = workspace_command.start_transaction("fetch from git remote into empty repo");