Skip to content

Commit

Permalink
rewrite: calculate heads_to_add later, remove it from state
Browse files Browse the repository at this point in the history
Similar to the previous two commits.
  • Loading branch information
martinvonz committed Mar 26, 2024
1 parent 2ee1147 commit 718e54b
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions lib/src/rewrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,6 @@ pub(crate) struct DescendantRebaser<'settings, 'repo> {
rebased: HashMap<CommitId, CommitId>,
// Names of branches where local target includes the commit id in the key.
branches: HashMap<CommitId, HashSet<String>>,
// Parents of rebased/abandoned commit that should become new heads once their descendants
// have been rebased.
heads_to_add: HashSet<CommitId>,

// Options to apply during a rebase.
options: RebaseOptions,
Expand All @@ -307,15 +304,6 @@ impl<'settings, 'repo> DescendantRebaser<'settings, 'repo> {
RevsetExpression::commits(mut_repo.parent_mapping.keys().cloned().collect()).union(
&RevsetExpression::commits(mut_repo.abandoned.iter().cloned().collect()),
);
let heads_to_add_expression = old_commits_expression
.parents()
.minus(&old_commits_expression);
let heads_to_add = heads_to_add_expression
.evaluate_programmatic(mut_repo)
.unwrap()
.iter()
.collect();

let to_visit_expression = old_commits_expression.descendants();
let to_visit_revset = to_visit_expression.evaluate_programmatic(mut_repo).unwrap();
let to_visit: Vec<_> = to_visit_revset.iter().commits(store).try_collect().unwrap();
Expand Down Expand Up @@ -365,7 +353,6 @@ impl<'settings, 'repo> DescendantRebaser<'settings, 'repo> {
to_visit,
rebased: Default::default(),
branches,
heads_to_add,
options: Default::default(),
}
}
Expand Down Expand Up @@ -516,9 +503,23 @@ impl<'settings, 'repo> DescendantRebaser<'settings, 'repo> {
.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(),
));
let heads_to_add_expression = old_commits_expression
.parents()
.minus(&old_commits_expression);
let mut heads_to_add: HashSet<_> = 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() {
self.heads_to_add.remove(old_parent_id);
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());
}
Expand All @@ -528,10 +529,7 @@ impl<'settings, 'repo> DescendantRebaser<'settings, 'repo> {
for commit_id in &heads_to_remove {
view.head_ids.remove(commit_id);
}
for commit_id in &self.heads_to_add {
view.head_ids.insert(commit_id.clone());
}
self.heads_to_add.clear();
view.head_ids.extend(heads_to_add);
self.mut_repo.set_view(view);
}

Expand Down

0 comments on commit 718e54b

Please sign in to comment.