Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preparations for moving DescendantRebaser state into MutableRepo #3356

Merged
merged 6 commits into from
Mar 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions lib/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = CommitId>,
) {
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
Expand Down Expand Up @@ -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);
martinvonz marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down