From 24b1421918ad1da289ec69cec3b4a471ac087a34 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Tue, 12 Dec 2023 23:35:29 -0800 Subject: [PATCH] cli: move a few transaction description variables later Now that we don't need the transaction until later, let's move the variables closer to where they're used. --- cli/src/commands/abandon.rs | 22 +++++++++++----------- cli/src/commands/rebase.rs | 16 ++++++++-------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/cli/src/commands/abandon.rs b/cli/src/commands/abandon.rs index 3e4483377..c5e86162e 100644 --- a/cli/src/commands/abandon.rs +++ b/cli/src/commands/abandon.rs @@ -49,15 +49,6 @@ pub(crate) fn cmd_abandon( let mut workspace_command = command.workspace_helper(ui)?; let to_abandon = resolve_multiple_nonempty_revsets(&args.revisions, &workspace_command, ui)?; workspace_command.check_rewritable(to_abandon.iter())?; - let transaction_description = if to_abandon.len() == 1 { - format!("abandon commit {}", to_abandon[0].id().hex()) - } else { - format!( - "abandon commit {} and {} more", - to_abandon[0].id().hex(), - to_abandon.len() - 1 - ) - }; let mut tx = workspace_command.start_transaction(); for commit in &to_abandon { tx.mut_repo().record_abandoned_commit(commit.id().clone()); @@ -71,10 +62,10 @@ pub(crate) fn cmd_abandon( writeln!(ui.stderr())?; } else if !args.summary { writeln!(ui.stderr(), "Abandoned the following commits:")?; - for commit in to_abandon { + for commit in &to_abandon { write!(ui.stderr(), " ")?; tx.base_workspace_helper() - .write_commit_summary(ui.stderr_formatter().as_mut(), &commit)?; + .write_commit_summary(ui.stderr_formatter().as_mut(), commit)?; writeln!(ui.stderr())?; } } else { @@ -86,6 +77,15 @@ pub(crate) fn cmd_abandon( "Rebased {num_rebased} descendant commits onto parents of abandoned commits" )?; } + let transaction_description = if to_abandon.len() == 1 { + format!("abandon commit {}", to_abandon[0].id().hex()) + } else { + format!( + "abandon commit {} and {} more", + to_abandon[0].id().hex(), + to_abandon.len() - 1 + ) + }; tx.finish(ui, transaction_description)?; Ok(()) } diff --git a/cli/src/commands/rebase.rs b/cli/src/commands/rebase.rs index f20cd1908..2a8ee8378 100644 --- a/cli/src/commands/rebase.rs +++ b/cli/src/commands/rebase.rs @@ -277,14 +277,6 @@ fn rebase_descendants( for old_commit in old_commits.iter() { check_rebase_destinations(workspace_command.repo(), new_parents, old_commit)?; } - let tx_message = if old_commits.len() == 1 { - format!( - "rebase commit {} and descendants", - old_commits.first().unwrap().id().hex() - ) - } else { - format!("rebase {} commits and their descendants", old_commits.len()) - }; let mut tx = workspace_command.start_transaction(); // `rebase_descendants` takes care of sorting in reverse topological order, so // no need to do it here. @@ -301,6 +293,14 @@ fn rebase_descendants( + tx.mut_repo() .rebase_descendants_with_options(settings, rebase_options)?; writeln!(ui.stderr(), "Rebased {num_rebased} commits")?; + let tx_message = if old_commits.len() == 1 { + format!( + "rebase commit {} and descendants", + old_commits.first().unwrap().id().hex() + ) + } else { + format!("rebase {} commits and their descendants", old_commits.len()) + }; tx.finish(ui, tx_message)?; Ok(()) }