Skip to content

Commit

Permalink
rewrite: avoid accessing MutRepo::view() when rebasing descendants
Browse files Browse the repository at this point in the history
Since 94e03f5, we lazily filter out non-heads from `View`'s set
of head. Accessing the `MutRepo::view()` triggers that filtering. This
patch makes `DescendantRebaser` not unnecessarily do that. That speeds
up the rebasing of 162 descendants in the git.git repo from ~3.6 s to
~330 ms. Rebasing 1272 descendants takes ~885 ms.
  • Loading branch information
martinvonz committed Dec 8, 2021
1 parent f084a05 commit c058ffe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,10 @@ impl MutableRepo {
)
}

pub fn get_checkout(&mut self) -> CommitId {
self.view.borrow().checkout().clone()
}

pub fn set_checkout(&mut self, id: CommitId) {
self.view_mut().set_checkout(id);
}
Expand Down
5 changes: 2 additions & 3 deletions lib/src/rewrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,18 +264,17 @@ impl<'settings, 'repo> DescendantRebaser<'settings, 'repo> {
}

fn update_references(&mut self, old_commit_id: CommitId, new_commit_ids: Vec<CommitId>) {
if *self.mut_repo.view().checkout() == old_commit_id {
if self.mut_repo.get_checkout() == old_commit_id {
// We arbitrarily pick a new checkout among the candidates.
let new_commit_id = new_commit_ids[0].clone();
let new_commit = self.mut_repo.store().get_commit(&new_commit_id).unwrap();
self.mut_repo.check_out(self.settings, &new_commit);
}

if let Some(branch_names) = self.branches.get(&old_commit_id) {
let view = self.mut_repo.view();
let mut branch_updates = vec![];
for branch_name in branch_names {
let local_target = view.get_local_branch(branch_name).unwrap();
let local_target = self.mut_repo.get_local_branch(branch_name).unwrap();
for old_add in local_target.adds() {
if old_add == old_commit_id {
branch_updates.push((branch_name.clone(), true));
Expand Down

0 comments on commit c058ffe

Please sign in to comment.