Skip to content

Commit

Permalink
commit_builder: inline mut_repo.write_commit()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
yuja committed Jul 20, 2024
1 parent 2e3b4b5 commit 9d5eda1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
5 changes: 2 additions & 3 deletions lib/src/commit_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 2 additions & 13 deletions lib/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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>;
Expand Down Expand Up @@ -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.
///
Expand Down

0 comments on commit 9d5eda1

Please sign in to comment.