mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-27 06:27:43 +00:00
transaction: add factory function to MutableRepo
This helps finish the encapsulate of the `evolution` field.
This commit is contained in:
parent
5604303954
commit
bf53c6c506
1 changed files with 25 additions and 18 deletions
|
@ -47,27 +47,13 @@ impl<'r> Transaction<'r> {
|
|||
evolution: &ReadonlyEvolution<'r>,
|
||||
description: &str,
|
||||
) -> Transaction<'r> {
|
||||
let mut_view = view.start_modification();
|
||||
let internal = Arc::new(MutableRepo {
|
||||
repo,
|
||||
view: Some(mut_view),
|
||||
evolution: None,
|
||||
});
|
||||
let repo_ref: &MutableRepo = internal.as_ref();
|
||||
let static_lifetime_repo: &'static MutableRepo = unsafe { std::mem::transmute(repo_ref) };
|
||||
let mut tx = Transaction {
|
||||
repo: Some(internal),
|
||||
let mut_repo = MutableRepo::new(repo, view, evolution);
|
||||
Transaction {
|
||||
repo: Some(mut_repo),
|
||||
description: description.to_owned(),
|
||||
start_time: Timestamp::now(),
|
||||
closed: false,
|
||||
};
|
||||
let mut_evolution: MutableEvolution<'_, '_> =
|
||||
evolution.start_modification(static_lifetime_repo);
|
||||
let static_lifetime_mut_evolution: MutableEvolution<'static, 'static> =
|
||||
unsafe { std::mem::transmute(mut_evolution) };
|
||||
Arc::get_mut(tx.repo.as_mut().unwrap()).unwrap().evolution =
|
||||
Some(static_lifetime_mut_evolution);
|
||||
tx
|
||||
}
|
||||
}
|
||||
|
||||
pub fn base_repo(&self) -> &'r ReadonlyRepo {
|
||||
|
@ -224,6 +210,27 @@ impl<'r> Repo for MutableRepo<'r> {
|
|||
}
|
||||
|
||||
impl<'r> MutableRepo<'r> {
|
||||
pub fn new(
|
||||
repo: &'r ReadonlyRepo,
|
||||
view: &ReadonlyView,
|
||||
evolution: &ReadonlyEvolution<'r>,
|
||||
) -> Arc<MutableRepo<'r>> {
|
||||
let mut_view = view.start_modification();
|
||||
let mut mut_repo = Arc::new(MutableRepo {
|
||||
repo,
|
||||
view: Some(mut_view),
|
||||
evolution: None,
|
||||
});
|
||||
let repo_ref: &MutableRepo = mut_repo.as_ref();
|
||||
let static_lifetime_repo: &'static MutableRepo = unsafe { std::mem::transmute(repo_ref) };
|
||||
let mut_evolution: MutableEvolution<'_, '_> =
|
||||
evolution.start_modification(static_lifetime_repo);
|
||||
let static_lifetime_mut_evolution: MutableEvolution<'static, 'static> =
|
||||
unsafe { std::mem::transmute(mut_evolution) };
|
||||
Arc::get_mut(&mut mut_repo).unwrap().evolution = Some(static_lifetime_mut_evolution);
|
||||
mut_repo
|
||||
}
|
||||
|
||||
pub fn base_repo(&self) -> &'r ReadonlyRepo {
|
||||
self.repo
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue