From 9d5eda107d27f899a9aabe25fe647cbd7d34cf62 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Fri, 19 Jul 2024 15:39:30 +0900 Subject: [PATCH] commit_builder: inline mut_repo.write_commit() As the doc comment says, it's called only from CommitBuilder. Let's clarify that. I'm also planning to extract a builder that only writes to the store (without mutably borrowing a mut_repo.) It will help implement description template. --- lib/src/commit_builder.rs | 5 ++--- lib/src/repo.rs | 15 ++------------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/lib/src/commit_builder.rs b/lib/src/commit_builder.rs index c9fe0752c1..ec6ce6a691 100644 --- a/lib/src/commit_builder.rs +++ b/lib/src/commit_builder.rs @@ -205,9 +205,8 @@ impl CommitBuilder<'_> { // if we're rewriting a signed commit self.commit.secure_sig = None; - let commit = self - .mut_repo - .write_commit(self.commit, signing_fn.as_deref_mut())?; + let commit = store.write_commit(self.commit, signing_fn.as_deref_mut())?; + self.mut_repo.add_head(&commit)?; if let Some(rewrite_source) = self.rewrite_source { if rewrite_source.change_id() == commit.change_id() { self.mut_repo diff --git a/lib/src/repo.rs b/lib/src/repo.rs index 60165ffe4a..dc8f28e404 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -30,7 +30,7 @@ use tracing::instrument; use self::dirty_cell::DirtyCell; use crate::backend::{ Backend, BackendError, BackendInitError, BackendLoadError, BackendResult, ChangeId, CommitId, - MergedTreeId, SigningFn, + MergedTreeId, }; use crate::commit::{Commit, CommitByCommitterTimestamp}; use crate::commit_builder::CommitBuilder; @@ -58,7 +58,7 @@ use crate::store::Store; use crate::submodule_store::SubmoduleStore; use crate::transaction::Transaction; use crate::view::View; -use crate::{backend, dag_walk, op_store, revset}; +use crate::{dag_walk, op_store, revset}; pub trait Repo { fn store(&self) -> &Arc; @@ -831,17 +831,6 @@ impl MutableRepo { // `self.rewritten_commits` } - /// Only called from [`CommitBuilder::write`]. Use that function instead. - pub(crate) fn write_commit( - &mut self, - commit: backend::Commit, - sign_with: Option<&mut SigningFn>, - ) -> BackendResult { - let commit = self.store().write_commit(commit, sign_with)?; - self.add_head(&commit)?; - Ok(commit) - } - /// Record a commit as having been rewritten to another commit in this /// transaction. ///