From 7319479df97faa2c8c3462e89e5d4de16d813320 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sat, 20 Apr 2024 13:41:11 -0700 Subject: [PATCH] squash: decide to abandon source commit if entire diff was selected Before this patch, we would abandon the source commit if it became empty after applying the reverse diff. This changes that condition to the equivalent condition of the selected tree being the source commit's original tree. This will help us rewrite the code to use `transform_descendants()`. --- cli/src/commands/squash.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cli/src/commands/squash.rs b/cli/src/commands/squash.rs index 4972cc82a..17a22dde0 100644 --- a/cli/src/commands/squash.rs +++ b/cli/src/commands/squash.rs @@ -203,15 +203,15 @@ from the source will be moved into the destination. tx.format_commit_summary(source), tx.format_commit_summary(destination) ); - let new_parent_tree_id = + let selected_tree_id = diff_selector.select(&parent_tree, &source_tree, matcher, Some(&instructions))?; - let new_parent_tree = tx.repo().store().get_root_tree(&new_parent_tree_id)?; + let selected_tree = tx.repo().store().get_root_tree(&selected_tree_id)?; + let abandon_source = selected_tree.id() == source_tree.id(); // TODO: Do we want to optimize the case of moving to the parent commit (`jj // squash -r`)? The source tree will be unchanged in that case. // Apply the reverse of the selected changes onto the source - let new_source_tree = source_tree.merge(&new_parent_tree, &parent_tree)?; - let abandon_source = new_source_tree.id() == parent_tree.id(); + let new_source_tree = source_tree.merge(&selected_tree, &parent_tree)?; if abandon_source { abandoned_commits.push(source); tx.mut_repo().record_abandoned_commit(source.id().clone()); @@ -221,8 +221,8 @@ from the source will be moved into the destination. .set_tree_id(new_source_tree.id().clone()) .write()?; } - if new_parent_tree_id != parent_tree.id() { - tree_diffs.push((parent_tree, new_parent_tree)); + if selected_tree_id != parent_tree.id() { + tree_diffs.push((parent_tree, selected_tree)); } } if tree_diffs.is_empty() {