From 5e7a4a20281b93b5871c1bc700406e99e8896247 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sun, 24 Mar 2024 23:18:43 -0700 Subject: [PATCH] rewrite: update heads outside `update_references()` Now that we only call `update_references()` in one place, there's no reason to have it also update `heads_to_add` and `heads_to_remove`. By moving it out of the function, we can consolidate the logic in one place. --- lib/src/rewrite.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/src/rewrite.rs b/lib/src/rewrite.rs index 673d9f4b8..ce93656aa 100644 --- a/lib/src/rewrite.rs +++ b/lib/src/rewrite.rs @@ -421,17 +421,13 @@ impl<'settings, 'repo> DescendantRebaser<'settings, 'repo> { } } let (old_target, new_target) = - DescendantRebaser::ref_target_update(old_commit_id.clone(), new_commit_ids); + DescendantRebaser::ref_target_update(old_commit_id, new_commit_ids); for branch_name in &branch_updates { self.mut_repo .merge_local_branch(branch_name, &old_target, &new_target); } } - self.heads_to_add.remove(&old_commit_id); - if !self.new_commits.contains(&old_commit_id) || self.rebased.contains_key(&old_commit_id) { - self.heads_to_remove.push(old_commit_id); - } Ok(()) } @@ -523,6 +519,13 @@ impl<'settings, 'repo> DescendantRebaser<'settings, 'repo> { } fn update_heads(&mut self) { + for old_parent_id in self.mut_repo.parent_mapping.keys() { + self.heads_to_add.remove(old_parent_id); + if !self.new_commits.contains(old_parent_id) || self.rebased.contains_key(old_parent_id) { + self.heads_to_remove.push(old_parent_id.clone()); + } + } + let mut view = self.mut_repo.view().store_view().clone(); for commit_id in &self.heads_to_remove { view.head_ids.remove(commit_id);