cli: don't start transaction before snapshotting working copy

In the `jj git push --change X` code, we start a transaction and then
resolve the argument, which often results in the working copy getting
snapshotted. Since the snapshotting happens in its own transaction,
that means we have two concurrent operations for no good reason. This
patch fixes that by starting the main transaction a little
later. Since that restructuring made it easy to give more detailed
descriptions to the operations, I also did that.
This commit is contained in:
Martin von Zweigbergk 2022-07-04 23:42:40 -07:00 committed by Martin von Zweigbergk
parent 75dc65c30f
commit be15d167c6

View file

@ -5084,8 +5084,7 @@ fn cmd_git_push(
let mut workspace_command = command.workspace_helper(ui)?; let mut workspace_command = command.workspace_helper(ui)?;
let repo = workspace_command.repo().clone(); let repo = workspace_command.repo().clone();
let mut tx = let mut tx;
workspace_command.start_transaction(&format!("push to git remote {}", &args.remote));
let mut branch_updates = vec![]; let mut branch_updates = vec![];
if let Some(branch_name) = &args.branch { if let Some(branch_name) = &args.branch {
if let Some(update) = if let Some(update) =
@ -5099,6 +5098,10 @@ fn cmd_git_push(
branch_name, &args.remote, branch_name branch_name, &args.remote, branch_name
)?; )?;
} }
tx = workspace_command.start_transaction(&format!(
"push branch {branch_name} to git remote {}",
&args.remote
));
} else if let Some(change_str) = &args.change { } else if let Some(change_str) = &args.change {
let commit = workspace_command.resolve_single_rev(ui, change_str)?; let commit = workspace_command.resolve_single_rev(ui, change_str)?;
let branch_name = format!( let branch_name = format!(
@ -5106,13 +5109,18 @@ fn cmd_git_push(
ui.settings().push_branch_prefix(), ui.settings().push_branch_prefix(),
commit.change_id().hex() commit.change_id().hex()
); );
if tx.mut_repo().get_local_branch(&branch_name).is_none() { if repo.view().get_local_branch(&branch_name).is_none() {
writeln!( writeln!(
ui, ui,
"Creating branch {} for revision {}", "Creating branch {} for revision {}",
branch_name, change_str branch_name, change_str
)?; )?;
} }
tx = workspace_command.start_transaction(&format!(
"push change {} to git remote {}",
commit.change_id().hex(),
&args.remote
));
tx.mut_repo() tx.mut_repo()
.set_local_branch(branch_name.clone(), RefTarget::Normal(commit.id().clone())); .set_local_branch(branch_name.clone(), RefTarget::Normal(commit.id().clone()));
if let Some(update) = if let Some(update) =
@ -5139,6 +5147,8 @@ fn cmd_git_push(
} }
} }
} }
tx = workspace_command
.start_transaction(&format!("push all branches to git remote {}", &args.remote));
} }
if branch_updates.is_empty() { if branch_updates.is_empty() {