From d0cbe356c9600843808c57d3d3b2985fe82be7a3 Mon Sep 17 00:00:00 2001 From: Evan Mesterhazy Date: Fri, 1 Mar 2024 18:34:16 -0500 Subject: [PATCH] Make a minor simplification to CommitBuilder::write There's no need to have a block of code at the beginning of the function to cache the rewrite source id. We can simply check the necessary condition before calling record_rewritten_commit. This tweak makes the function a little easier to read since we don't check the condition until we're ready to do the work. --- lib/src/commit_builder.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/src/commit_builder.rs b/lib/src/commit_builder.rs index 7a6ea1d2bb..6071ffda9a 100644 --- a/lib/src/commit_builder.rs +++ b/lib/src/commit_builder.rs @@ -178,13 +178,6 @@ impl CommitBuilder<'_> { } pub fn write(mut self) -> BackendResult { - let mut rewrite_source_id = None; - if let Some(rewrite_source) = self.rewrite_source { - if *rewrite_source.change_id() == self.commit.change_id { - rewrite_source_id.replace(rewrite_source.id().clone()); - } - } - let sign_settings = &self.sign_settings; let store = self.mut_repo.store(); @@ -202,9 +195,11 @@ impl CommitBuilder<'_> { let commit = self .mut_repo .write_commit(self.commit, signing_fn.as_deref_mut())?; - if let Some(rewrite_source_id) = rewrite_source_id { - self.mut_repo - .record_rewritten_commit(rewrite_source_id, commit.id().clone()) + if let Some(rewrite_source) = self.rewrite_source { + if rewrite_source.change_id() == commit.change_id() { + self.mut_repo + .record_rewritten_commit(rewrite_source.id().clone(), commit.id().clone()); + } } Ok(commit) }