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

rewrite: simplify update_heads() #3397

Merged
merged 4 commits into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions lib/src/repo.rs
martinvonz marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,7 @@ impl MutableRepo {
pub fn set_rewritten_commit(&mut self, old_id: CommitId, new_id: CommitId) {
assert_ne!(old_id, *self.store().root_commit_id());
self.divergent.remove(&old_id);
self.abandoned.remove(&old_id);
self.parent_mapping.insert(old_id, vec![new_id]);
}

Expand All @@ -843,6 +844,7 @@ impl MutableRepo {
new_ids: impl IntoIterator<Item = CommitId>,
) {
assert_ne!(old_id, *self.store().root_commit_id());
self.abandoned.remove(&old_id);
self.parent_mapping
.insert(old_id.clone(), new_ids.into_iter().collect());
self.divergent.insert(old_id);
Expand Down
32 changes: 5 additions & 27 deletions lib/src/rewrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,7 @@ impl<'settings, 'repo> DescendantRebaser<'settings, 'repo> {
) -> DescendantRebaser<'settings, 'repo> {
let store = mut_repo.store();
let old_commits_expression =
RevsetExpression::commits(mut_repo.parent_mapping.keys().cloned().collect()).union(
&RevsetExpression::commits(mut_repo.abandoned.iter().cloned().collect()),
);
RevsetExpression::commits(mut_repo.parent_mapping.keys().cloned().collect());
let to_visit_expression = old_commits_expression
.descendants()
.minus(&old_commits_expression);
Expand Down Expand Up @@ -490,38 +488,18 @@ impl<'settings, 'repo> DescendantRebaser<'settings, 'repo> {
}

fn update_heads(&mut self) {
let new_commits: HashSet<_> = self
.mut_repo
.parent_mapping
.values()
.flatten()
.cloned()
.collect();

let old_commits_expression =
RevsetExpression::commits(self.mut_repo.parent_mapping.keys().cloned().collect())
.union(&RevsetExpression::commits(
self.mut_repo.abandoned.iter().cloned().collect(),
));
RevsetExpression::commits(self.mut_repo.parent_mapping.keys().cloned().collect());
let heads_to_add_expression = old_commits_expression
.parents()
.minus(&old_commits_expression);
let mut heads_to_add: HashSet<_> = heads_to_add_expression
let heads_to_add = heads_to_add_expression
.evaluate_programmatic(self.mut_repo)
.unwrap()
.iter()
.collect();

let mut heads_to_remove = vec![];
for old_parent_id in self.mut_repo.parent_mapping.keys() {
heads_to_add.remove(old_parent_id);
if !new_commits.contains(old_parent_id) || self.rebased.contains_key(old_parent_id) {
heads_to_remove.push(old_parent_id.clone());
}
}
.iter();

let mut view = self.mut_repo.view().store_view().clone();
for commit_id in &heads_to_remove {
for commit_id in self.mut_repo.parent_mapping.keys() {
view.head_ids.remove(commit_id);
}
view.head_ids.extend(heads_to_add);
Expand Down