Skip to content

Commit

Permalink
Make a minor simplification to CommitBuilder::write
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
emesterhazy committed Mar 1, 2024
1 parent 5c252bd commit d0cbe35
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions lib/src/commit_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,6 @@ impl CommitBuilder<'_> {
}

pub fn write(mut self) -> BackendResult<Commit> {
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();

Expand All @@ -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)
}
Expand Down

0 comments on commit d0cbe35

Please sign in to comment.