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.
This commit is contained in:
Yuya Nishihara 2024-07-19 15:39:30 +09:00
parent 2e3b4b5fe3
commit 9d5eda107d
2 changed files with 4 additions and 16 deletions

View file

@ -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

View file

@ -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<Store>;
@ -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<Commit> {
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.
///