From e62338ce80d6d61f88e211b1ac5c789e79a08dfe Mon Sep 17 00:00:00 2001 From: Ilya Grigoriev Date: Fri, 22 Dec 2023 17:39:21 -0800 Subject: [PATCH] lib: mild refactoring made possible by previous commit Inline `create_descendant_commits`, move some functionality of `DescendantRebaser::rebase_next` to `rebase_all`, a seemingly more logical location. --- lib/src/repo.rs | 22 ++++++---------------- lib/src/rewrite.rs | 10 +++++----- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/lib/src/repo.rs b/lib/src/repo.rs index d5420c288a..0ebb31e69e 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -861,21 +861,6 @@ impl MutableRepo { !(self.rewritten_commits.is_empty() && self.abandoned_commits.is_empty()) } - /// Creates a `DescendantRebaser` to rebase descendants of the recorded - /// rewritten and abandoned commits. - // TODO(ilyagr): Inline this. It's only used in tests. - fn create_descendant_rebaser<'settings, 'repo>( - &'repo mut self, - settings: &'settings UserSettings, - ) -> DescendantRebaser<'settings, 'repo> { - DescendantRebaser::new( - settings, - self, - self.rewritten_commits.clone(), - self.abandoned_commits.clone(), - ) - } - fn rebase_descendants_return_rebaser<'settings, 'repo>( &'repo mut self, settings: &'settings UserSettings, @@ -885,7 +870,12 @@ impl MutableRepo { // Optimization return Ok(None); } - let mut rebaser = self.create_descendant_rebaser(settings); + let mut rebaser = DescendantRebaser::new( + settings, + self, + self.rewritten_commits.clone(), + self.abandoned_commits.clone(), + ); *rebaser.mut_options() = options; rebaser.rebase_all()?; Ok(Some(rebaser)) diff --git a/lib/src/rewrite.rs b/lib/src/rewrite.rs index d2bccc89be..eeeb474d17 100644 --- a/lib/src/rewrite.rs +++ b/lib/src/rewrite.rs @@ -587,6 +587,11 @@ impl<'settings, 'repo> DescendantRebaser<'settings, 'repo> { new_commit, })); } + Ok(None) + } + + pub fn rebase_all(&mut self) -> Result<(), TreeMergeError> { + while self.rebase_next()?.is_some() {} // TODO: As the TODO above says, we should probably change the API. Even if we // don't, we should at least make this code not do any work if you call // rebase_next() after we've returned None. @@ -600,11 +605,6 @@ impl<'settings, 'repo> DescendantRebaser<'settings, 'repo> { self.heads_to_remove.clear(); self.heads_to_add.clear(); self.mut_repo.set_view(view); - Ok(None) - } - - pub fn rebase_all(&mut self) -> Result<(), TreeMergeError> { - while self.rebase_next()?.is_some() {} Ok(()) } }