diff --git a/lib/src/commit_builder.rs b/lib/src/commit_builder.rs index 704866cfb..7fcf0c935 100644 --- a/lib/src/commit_builder.rs +++ b/lib/src/commit_builder.rs @@ -154,7 +154,7 @@ impl CommitBuilder { self } - pub fn write_to_new_transaction(self, repo: &ReadonlyRepo, description: &str) -> Commit { + pub fn write_to_new_transaction(self, repo: &Arc, description: &str) -> Commit { let mut tx = repo.start_transaction(description); let commit = self.write_to_repo(tx.mut_repo()); tx.commit(); diff --git a/lib/src/repo.rs b/lib/src/repo.rs index 34859584f..d3a01439d 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -64,20 +64,20 @@ pub type RepoResult = Result; // TODO: Should we implement From<&ReadonlyRepo> and From<&MutableRepo> for // RepoRef? #[derive(Clone, Copy)] -pub enum RepoRef<'a, 'r: 'a> { +pub enum RepoRef<'a> { Readonly(&'a ReadonlyRepo), - Mutable(&'a MutableRepo<'r>), + Mutable(&'a MutableRepo), } -impl<'a, 'r> RepoRef<'a, 'r> { - pub fn store(&self) -> &'a Arc { +impl<'a> RepoRef<'a> { + pub fn store(&self) -> &Arc { match self { RepoRef::Readonly(repo) => repo.store(), RepoRef::Mutable(repo) => repo.store(), } } - pub fn op_store(&self) -> &'a Arc { + pub fn op_store(&self) -> &Arc { match self { RepoRef::Readonly(repo) => repo.op_store(), RepoRef::Mutable(repo) => repo.op_store(), @@ -346,9 +346,14 @@ impl ReadonlyRepo { &self.settings } - pub fn start_transaction(&self, description: &str) -> Transaction { + pub fn start_transaction(self: &Arc, description: &str) -> Transaction { let locked_evolution = self.evolution.lock().unwrap(); - let mut_repo = MutableRepo::new(self, self.index(), &self.view, locked_evolution.as_ref()); + let mut_repo = MutableRepo::new( + self.clone(), + self.index(), + &self.view, + locked_evolution.as_ref(), + ); Transaction::new(mut_repo, description) } @@ -469,20 +474,20 @@ impl RepoLoader { } } -pub struct MutableRepo<'r> { - base_repo: &'r ReadonlyRepo, +pub struct MutableRepo { + base_repo: Arc, index: MutableIndex, view: MutableView, evolution: Mutex>, } -impl<'r> MutableRepo<'r> { +impl MutableRepo { pub fn new( - base_repo: &'r ReadonlyRepo, + base_repo: Arc, index: Arc, view: &ReadonlyView, evolution: Option<&Arc>, - ) -> Arc> { + ) -> Arc { let mut_view = view.start_modification(); let mut_index = MutableIndex::incremental(index); let mut_evolution = evolution.map(|evolution| evolution.start_modification()); @@ -498,8 +503,8 @@ impl<'r> MutableRepo<'r> { RepoRef::Mutable(&self) } - pub fn base_repo(&self) -> &'r ReadonlyRepo { - self.base_repo + pub fn base_repo(&self) -> &Arc { + &self.base_repo } pub fn store(&self) -> &Arc { diff --git a/lib/src/transaction.rs b/lib/src/transaction.rs index 14e37408b..74271f8d5 100644 --- a/lib/src/transaction.rs +++ b/lib/src/transaction.rs @@ -21,16 +21,16 @@ use crate::operation::Operation; use crate::repo::{MutableRepo, ReadonlyRepo}; use crate::store::Timestamp; -pub struct Transaction<'r> { - repo: Option>>, +pub struct Transaction { + repo: Option>, parents: Vec, description: String, start_time: Timestamp, closed: bool, } -impl<'r> Transaction<'r> { - pub fn new(mut_repo: Arc>, description: &str) -> Transaction<'r> { +impl Transaction { + pub fn new(mut_repo: Arc, description: &str) -> Transaction { let parents = vec![mut_repo.base_repo().op_id().clone()]; Transaction { repo: Some(mut_repo), @@ -41,7 +41,7 @@ impl<'r> Transaction<'r> { } } - pub fn base_repo(&self) -> &'r ReadonlyRepo { + pub fn base_repo(&self) -> &ReadonlyRepo { self.repo.as_ref().unwrap().base_repo() } @@ -49,7 +49,7 @@ impl<'r> Transaction<'r> { self.parents = parents; } - pub fn mut_repo(&mut self) -> &mut MutableRepo<'r> { + pub fn mut_repo(&mut self) -> &mut MutableRepo { Arc::get_mut(self.repo.as_mut().unwrap()).unwrap() } @@ -63,7 +63,7 @@ impl<'r> Transaction<'r> { /// operation will not be seen when loading the repo at head. pub fn write(mut self) -> UnpublishedOperation { let mut_repo = Arc::try_unwrap(self.repo.take().unwrap()).ok().unwrap(); - let base_repo = mut_repo.base_repo(); + let base_repo = mut_repo.base_repo().clone(); let (mut_index, mut_view) = mut_repo.consume(); let index = base_repo.index_store().write_index(mut_index).unwrap(); @@ -97,7 +97,7 @@ impl<'r> Transaction<'r> { } } -impl Drop for Transaction<'_> { +impl Drop for Transaction { fn drop(&mut self) { if !std::thread::panicking() { debug_assert!(self.closed, "Transaction was dropped without being closed."); diff --git a/lib/tests/test_working_copy.rs b/lib/tests/test_working_copy.rs index fdec1e5f3..e73f31521 100644 --- a/lib/tests/test_working_copy.rs +++ b/lib/tests/test_working_copy.rs @@ -16,6 +16,7 @@ use std::fs::OpenOptions; use std::io::Write; #[cfg(unix)] use std::os::unix::fs::PermissionsExt; +use std::sync::Arc; use jujube_lib::commit_builder::CommitBuilder; use jujube_lib::repo::ReadonlyRepo; @@ -73,7 +74,7 @@ fn test_checkout_file_transitions(use_git: bool) { fn write_path( settings: &UserSettings, - repo: &ReadonlyRepo, + repo: &Arc, tree_builder: &mut TreeBuilder, kind: Kind, path: &str, diff --git a/src/template_parser.rs b/src/template_parser.rs index 1d3beda90..06e8175be 100644 --- a/src/template_parser.rs +++ b/src/template_parser.rs @@ -213,10 +213,7 @@ impl<'a, I: 'a> Property<'a, I> { } } -fn parse_commit_keyword<'a, 'r: 'a>( - repo: RepoRef<'a, 'r>, - pair: Pair, -) -> (Property<'a, Commit>, String) { +fn parse_commit_keyword<'a>(repo: RepoRef<'a>, pair: Pair) -> (Property<'a, Commit>, String) { assert_eq!(pair.as_rule(), Rule::identifier); let property = match pair.as_str() { "description" => Property::String(Box::new(DescriptionProperty)), @@ -257,8 +254,8 @@ fn coerce_to_string<'a, I: 'a>( } } -fn parse_boolean_commit_property<'a, 'r: 'a>( - repo: RepoRef<'a, 'r>, +fn parse_boolean_commit_property<'a>( + repo: RepoRef<'a>, pair: Pair, ) -> Box + 'a> { let mut inner = pair.into_inner(); @@ -274,10 +271,7 @@ fn parse_boolean_commit_property<'a, 'r: 'a>( } } -fn parse_commit_term<'a, 'r: 'a>( - repo: RepoRef<'a, 'r>, - pair: Pair, -) -> Box + 'a> { +fn parse_commit_term<'a>(repo: RepoRef<'a>, pair: Pair) -> Box + 'a> { assert_eq!(pair.as_rule(), Rule::term); if pair.as_str().is_empty() { Box::new(LiteralTemplate(String::new())) @@ -371,8 +365,8 @@ fn parse_commit_term<'a, 'r: 'a>( } } -fn parse_commit_template_rule<'a, 'r: 'a>( - repo: RepoRef<'a, 'r>, +fn parse_commit_template_rule<'a>( + repo: RepoRef<'a>, pair: Pair, ) -> Box + 'a> { match pair.as_rule() { @@ -394,8 +388,8 @@ fn parse_commit_template_rule<'a, 'r: 'a>( } } -pub fn parse_commit_template<'a, 'r: 'a>( - repo: RepoRef<'a, 'r>, +pub fn parse_commit_template<'a>( + repo: RepoRef<'a>, template_text: &str, ) -> Box + 'a> { let mut pairs: Pairs = TemplateParser::parse(Rule::template, template_text).unwrap(); diff --git a/src/templater.rs b/src/templater.rs index 1e535058f..4e62c0fc5 100644 --- a/src/templater.rs +++ b/src/templater.rs @@ -206,21 +206,21 @@ impl TemplateProperty for PrunedProperty { } } -pub struct CurrentCheckoutProperty<'a, 'r> { - pub repo: RepoRef<'a, 'r>, +pub struct CurrentCheckoutProperty<'a> { + pub repo: RepoRef<'a>, } -impl TemplateProperty for CurrentCheckoutProperty<'_, '_> { +impl TemplateProperty for CurrentCheckoutProperty<'_> { fn extract(&self, context: &Commit) -> bool { context.id() == self.repo.view().checkout() } } -pub struct GitRefsProperty<'a, 'r> { - pub repo: RepoRef<'a, 'r>, +pub struct GitRefsProperty<'a> { + pub repo: RepoRef<'a>, } -impl TemplateProperty for GitRefsProperty<'_, '_> { +impl TemplateProperty for GitRefsProperty<'_> { fn extract(&self, context: &Commit) -> String { let refs: Vec<_> = self .repo @@ -234,31 +234,31 @@ impl TemplateProperty for GitRefsProperty<'_, '_> { } } -pub struct ObsoleteProperty<'a, 'r> { - pub repo: RepoRef<'a, 'r>, +pub struct ObsoleteProperty<'a> { + pub repo: RepoRef<'a>, } -impl TemplateProperty for ObsoleteProperty<'_, '_> { +impl TemplateProperty for ObsoleteProperty<'_> { fn extract(&self, context: &Commit) -> bool { self.repo.evolution().is_obsolete(context.id()) } } -pub struct OrphanProperty<'a, 'r> { - pub repo: RepoRef<'a, 'r>, +pub struct OrphanProperty<'a> { + pub repo: RepoRef<'a>, } -impl TemplateProperty for OrphanProperty<'_, '_> { +impl TemplateProperty for OrphanProperty<'_> { fn extract(&self, context: &Commit) -> bool { self.repo.evolution().is_orphan(context.id()) } } -pub struct DivergentProperty<'a, 'r> { - pub repo: RepoRef<'a, 'r>, +pub struct DivergentProperty<'a> { + pub repo: RepoRef<'a>, } -impl TemplateProperty for DivergentProperty<'_, '_> { +impl TemplateProperty for DivergentProperty<'_> { fn extract(&self, context: &Commit) -> bool { self.repo.evolution().is_divergent(context.change_id()) }