From 3ddf9f43293552c2d0dad5e70eb29152e8a47e0b Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sat, 23 Mar 2024 14:49:29 -0700 Subject: [PATCH] repo: add parents of abandoned commit to parent_mapping By adding the abandoned commit's parents to `parent_mapping`, we can remove a bit more of the special handling of abandoned commitsin `DescendantRebaser`. --- lib/src/repo.rs | 8 +++++++- lib/src/rewrite.rs | 7 ------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/src/repo.rs b/lib/src/repo.rs index 2d9344fe2..838a65d5b 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -857,9 +857,15 @@ impl MutableRepo { /// The `rebase_descendants` logic will rebase the descendants of `old_id` /// to become the descendants of parent(s) of `old_id`. Any branches at /// `old_id` would be moved to the parent(s) of `old_id` as well. + // TODO: Propagate errors from commit lookup or take a Commit as argument. pub fn record_abandoned_commit(&mut self, old_id: CommitId) { assert_ne!(old_id, *self.store().root_commit_id()); - self.abandoned.insert(old_id); + self.divergent.remove(&old_id); + self.abandoned.insert(old_id.clone()); + // Descendants should be rebased onto the commit's parents + let old_commit = self.store().get_commit(&old_id).unwrap(); + self.parent_mapping + .insert(old_id, old_commit.parent_ids().to_vec()); } fn clear_descendant_rebaser_plans(&mut self) { diff --git a/lib/src/rewrite.rs b/lib/src/rewrite.rs index b7403a992..740b807f8 100644 --- a/lib/src/rewrite.rs +++ b/lib/src/rewrite.rs @@ -540,13 +540,6 @@ impl<'settings, 'repo> DescendantRebaser<'settings, 'repo> { } let old_parent_ids = old_commit.parent_ids(); let new_parent_ids = self.new_parents(old_parent_ids); - if self.mut_repo.abandoned.contains(&old_commit_id) { - // Update the `new_parents` map so descendants are rebased correctly. - self.mut_repo - .parent_mapping - .insert(old_commit_id.clone(), new_parent_ids.clone()); - return Ok(()); - } if new_parent_ids == old_parent_ids { // The commit is already in place. return Ok(());