mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-28 15:26:25 +00:00
commit_builder: keep Store internally
I'm going to extract an inner builder that is free from &mut MutableRepo lifetime.
This commit is contained in:
parent
49d92a0480
commit
fab310f53f
1 changed files with 9 additions and 5 deletions
|
@ -21,10 +21,12 @@ use crate::commit::Commit;
|
||||||
use crate::repo::{MutableRepo, Repo};
|
use crate::repo::{MutableRepo, Repo};
|
||||||
use crate::settings::{JJRng, SignSettings, UserSettings};
|
use crate::settings::{JJRng, SignSettings, UserSettings};
|
||||||
use crate::signing::SignBehavior;
|
use crate::signing::SignBehavior;
|
||||||
|
use crate::store::Store;
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub struct CommitBuilder<'repo> {
|
pub struct CommitBuilder<'repo> {
|
||||||
mut_repo: &'repo mut MutableRepo,
|
mut_repo: &'repo mut MutableRepo,
|
||||||
|
store: Arc<Store>,
|
||||||
rng: Arc<JJRng>,
|
rng: Arc<JJRng>,
|
||||||
commit: backend::Commit,
|
commit: backend::Commit,
|
||||||
rewrite_source: Option<Commit>,
|
rewrite_source: Option<Commit>,
|
||||||
|
@ -39,10 +41,11 @@ impl CommitBuilder<'_> {
|
||||||
parents: Vec<CommitId>,
|
parents: Vec<CommitId>,
|
||||||
tree_id: MergedTreeId,
|
tree_id: MergedTreeId,
|
||||||
) -> CommitBuilder<'repo> {
|
) -> CommitBuilder<'repo> {
|
||||||
|
let store = mut_repo.store().clone();
|
||||||
let signature = settings.signature();
|
let signature = settings.signature();
|
||||||
assert!(!parents.is_empty());
|
assert!(!parents.is_empty());
|
||||||
let rng = settings.get_rng();
|
let rng = settings.get_rng();
|
||||||
let change_id = rng.new_change_id(mut_repo.store().change_id_length());
|
let change_id = rng.new_change_id(store.change_id_length());
|
||||||
let commit = backend::Commit {
|
let commit = backend::Commit {
|
||||||
parents,
|
parents,
|
||||||
predecessors: vec![],
|
predecessors: vec![],
|
||||||
|
@ -55,6 +58,7 @@ impl CommitBuilder<'_> {
|
||||||
};
|
};
|
||||||
CommitBuilder {
|
CommitBuilder {
|
||||||
mut_repo,
|
mut_repo,
|
||||||
|
store,
|
||||||
rng,
|
rng,
|
||||||
commit,
|
commit,
|
||||||
rewrite_source: None,
|
rewrite_source: None,
|
||||||
|
@ -68,6 +72,7 @@ impl CommitBuilder<'_> {
|
||||||
settings: &UserSettings,
|
settings: &UserSettings,
|
||||||
predecessor: &Commit,
|
predecessor: &Commit,
|
||||||
) -> CommitBuilder<'repo> {
|
) -> CommitBuilder<'repo> {
|
||||||
|
let store = mut_repo.store().clone();
|
||||||
let mut commit = predecessor.store_commit().clone();
|
let mut commit = predecessor.store_commit().clone();
|
||||||
commit.predecessors = vec![predecessor.id().clone()];
|
commit.predecessors = vec![predecessor.id().clone()];
|
||||||
commit.committer = settings.signature();
|
commit.committer = settings.signature();
|
||||||
|
@ -96,6 +101,7 @@ impl CommitBuilder<'_> {
|
||||||
|
|
||||||
CommitBuilder {
|
CommitBuilder {
|
||||||
mut_repo,
|
mut_repo,
|
||||||
|
store,
|
||||||
commit,
|
commit,
|
||||||
rng: settings.get_rng(),
|
rng: settings.get_rng(),
|
||||||
rewrite_source: Some(predecessor.clone()),
|
rewrite_source: Some(predecessor.clone()),
|
||||||
|
@ -141,9 +147,7 @@ impl CommitBuilder<'_> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_new_change_id(mut self) -> Self {
|
pub fn generate_new_change_id(mut self) -> Self {
|
||||||
self.commit.change_id = self
|
self.commit.change_id = self.rng.new_change_id(self.store.change_id_length());
|
||||||
.rng
|
|
||||||
.new_change_id(self.mut_repo.store().change_id_length());
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,7 +194,7 @@ impl CommitBuilder<'_> {
|
||||||
|
|
||||||
pub fn write(mut self) -> BackendResult<Commit> {
|
pub fn write(mut self) -> BackendResult<Commit> {
|
||||||
let sign_settings = &self.sign_settings;
|
let sign_settings = &self.sign_settings;
|
||||||
let store = self.mut_repo.store();
|
let store = &self.store;
|
||||||
|
|
||||||
let should_sign = store.signer().can_sign() && sign_settings.should_sign(&self.commit);
|
let should_sign = store.signer().can_sign() && sign_settings.should_sign(&self.commit);
|
||||||
let sign_fn = |data: &[u8]| store.signer().sign(data, sign_settings.key.as_deref());
|
let sign_fn = |data: &[u8]| store.signer().sign(data, sign_settings.key.as_deref());
|
||||||
|
|
Loading…
Reference in a new issue