From be15d167c6fc9115f1d46a6e046cc78ec388b80f Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Mon, 4 Jul 2022 23:42:40 -0700 Subject: [PATCH] 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. --- src/commands.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index f788d6948..e8db37b7b 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -5084,8 +5084,7 @@ fn cmd_git_push( let mut workspace_command = command.workspace_helper(ui)?; let repo = workspace_command.repo().clone(); - let mut tx = - workspace_command.start_transaction(&format!("push to git remote {}", &args.remote)); + let mut tx; let mut branch_updates = vec![]; if let Some(branch_name) = &args.branch { if let Some(update) = @@ -5099,6 +5098,10 @@ fn cmd_git_push( 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 { let commit = workspace_command.resolve_single_rev(ui, change_str)?; let branch_name = format!( @@ -5106,13 +5109,18 @@ fn cmd_git_push( ui.settings().push_branch_prefix(), 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!( ui, "Creating branch {} for revision {}", branch_name, change_str )?; } + tx = workspace_command.start_transaction(&format!( + "push change {} to git remote {}", + commit.change_id().hex(), + &args.remote + )); tx.mut_repo() .set_local_branch(branch_name.clone(), RefTarget::Normal(commit.id().clone())); 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() {