From c058ffeed767c1dc194f4e51a792e44049ccfe4d Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Tue, 7 Dec 2021 22:14:44 -0800 Subject: [PATCH] rewrite: avoid accessing `MutRepo::view()` when rebasing descendants Since 94e03f5ac859, 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. --- lib/src/repo.rs | 4 ++++ lib/src/rewrite.rs | 5 ++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/src/repo.rs b/lib/src/repo.rs index 7cccabe9a..801ba2a57 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -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); } diff --git a/lib/src/rewrite.rs b/lib/src/rewrite.rs index 03acee381..c519af45c 100644 --- a/lib/src/rewrite.rs +++ b/lib/src/rewrite.rs @@ -264,7 +264,7 @@ impl<'settings, 'repo> DescendantRebaser<'settings, 'repo> { } fn update_references(&mut self, old_commit_id: CommitId, new_commit_ids: Vec) { - 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(); @@ -272,10 +272,9 @@ impl<'settings, 'repo> DescendantRebaser<'settings, 'repo> { } 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));