From 2f93de9299634fa433054dc535e7f14a9d01aabd Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Fri, 24 Nov 2023 18:37:21 +0900 Subject: [PATCH] rewrite: flatten mapping from EmptyBehaviour to desired action I think this is slightly easier to follow. --- lib/src/rewrite.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/src/rewrite.rs b/lib/src/rewrite.rs index 7c1ecfc49..a96f5bbd5 100644 --- a/lib/src/rewrite.rs +++ b/lib/src/rewrite.rs @@ -150,21 +150,21 @@ pub fn rebase_commit_with_options( // Ensure we don't abandon commits with multiple parents (merge commits), even // if they're empty. if let [parent] = new_parents { - match options.empty { - EmptyBehaviour::AbandonNewlyEmpty | EmptyBehaviour::AbandonAllEmpty => { - if *parent.tree_id() == new_tree_id - && (options.empty == EmptyBehaviour::AbandonAllEmpty - || old_base_tree_id != Some(old_commit.tree_id().clone())) - { - mut_repo.record_abandoned_commit(old_commit.id().clone()); - // Record old_commit as being succeeded by the parent for the purposes of - // the rebase. - // This ensures that when we stack commits, the second commit knows to - // rebase on top of the parent commit, rather than the abandoned commit. - return Ok(parent.clone()); - } + let should_abandon = match options.empty { + EmptyBehaviour::Keep => false, + EmptyBehaviour::AbandonNewlyEmpty => { + *parent.tree_id() == new_tree_id + && old_base_tree_id != Some(old_commit.tree_id().clone()) } - EmptyBehaviour::Keep => {} + EmptyBehaviour::AbandonAllEmpty => *parent.tree_id() == new_tree_id, + }; + if should_abandon { + mut_repo.record_abandoned_commit(old_commit.id().clone()); + // Record old_commit as being succeeded by the parent for the purposes of + // the rebase. + // This ensures that when we stack commits, the second commit knows to + // rebase on top of the parent commit, rather than the abandoned commit. + return Ok(parent.clone()); } } let new_parent_ids = new_parents