From af7ef4d04e609aefefd3c234c18830b20d8ec8b4 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sat, 23 Mar 2024 05:51:45 -0700 Subject: [PATCH] repo: add a method for explicitly recording divergent rewrite I plan to remove `record_rewritten_commit()` and instead make repeated rewrites replace the rewrite state. --- lib/src/repo.rs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/src/repo.rs b/lib/src/repo.rs index 56875c251..c2d362131 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -853,6 +853,24 @@ impl MutableRepo { .insert(new_id); } + /// Record a commit as being rewritten into multiple other commits in this + /// transaction. + /// + /// A later call to `rebase_descendants()` will update branches pointing to + /// `old_id` be conflicted and pointing to all pf `new_ids`. Working + /// copies pointing to `old_id` will be updated to point to an arbitrary + /// commit in `new_ids` (TODO: make it point to the first one). Descendants + /// of `old_id` will be left alone. + pub fn set_divergent_rewrite( + &mut self, + old_id: CommitId, + new_ids: impl IntoIterator, + ) { + assert_ne!(old_id, *self.store().root_commit_id()); + self.rewritten_commits + .insert(old_id, new_ids.into_iter().collect()); + } + /// Record a commit as having been abandoned in this transaction. /// /// This record is used by `rebase_descendants` to know which commits have @@ -1345,8 +1363,13 @@ impl MutableRepo { rewritten_changes.insert(change_id); } for (old_commit, new_commits) in rewritten_commits { - for new_commit in new_commits { - self.record_rewritten_commit(old_commit.clone(), new_commit); + if new_commits.len() == 1 { + self.record_rewritten_commit( + old_commit.clone(), + new_commits.into_iter().next().unwrap(), + ); + } else { + self.set_divergent_rewrite(old_commit.clone(), new_commits); } }