diff --git a/lib/src/rewrite.rs b/lib/src/rewrite.rs index 6915cb5bd..9e4b1c5ec 100644 --- a/lib/src/rewrite.rs +++ b/lib/src/rewrite.rs @@ -184,6 +184,14 @@ impl<'repo> CommitRewriter<'repo> { self.new_parents.retain(|parent| head_set.contains(parent)); } + /// Records the old commit as abandoned with the new parents. + pub fn abandon(self) { + let old_commit_id = self.old_commit.id().clone(); + let new_parents = self.new_parents; + self.mut_repo + .record_abandoned_commit_with_parents(old_commit_id, new_parents); + } + /// Rebase the old commit onto the new parents. Returns a `CommitBuilder` /// for the new commit. Returns `None` if the commit was abandoned. pub fn rebase_with_empty_behavior( @@ -235,10 +243,7 @@ impl<'repo> CommitRewriter<'repo> { EmptyBehaviour::AbandonAllEmpty => *parent.tree_id() == new_tree_id, }; if should_abandon { - self.mut_repo.record_abandoned_commit_with_parents( - self.old_commit.id().clone(), - std::iter::once(parent.id().clone()), - ); + self.abandon(); return Ok(None); } } diff --git a/lib/tests/test_rewrite_transform.rs b/lib/tests/test_rewrite_transform.rs index 58ebc7e76..87daa9775 100644 --- a/lib/tests/test_rewrite_transform.rs +++ b/lib/tests/test_rewrite_transform.rs @@ -50,11 +50,7 @@ fn test_transform_descendants_sync() { .transform_descendants(&settings, vec![commit_b.id().clone()], |mut rewriter| { rewriter.replace_parent(commit_a.id(), [commit_g.id()]); if *rewriter.old_commit() == commit_c { - let old_id = rewriter.old_commit().id().clone(); - let new_parent_ids = rewriter.new_parents().to_vec(); - rewriter - .mut_repo() - .record_abandoned_commit_with_parents(old_id, new_parent_ids); + rewriter.abandon(); } else { let old_commit_id = rewriter.old_commit().id().clone(); let new_commit = rewriter.rebase(&settings)?.write()?;