diff --git a/lib/src/op_heads_store.rs b/lib/src/op_heads_store.rs index ae4fddeaf..affd5eb3e 100644 --- a/lib/src/op_heads_store.rs +++ b/lib/src/op_heads_store.rs @@ -14,16 +14,17 @@ use crate::dag_walk; use crate::index::MutableIndex; -use crate::index_store::IndexStore; + use crate::lock::FileLock; use crate::op_store; use crate::op_store::{OpStore, OperationId, OperationMetadata}; use crate::operation::Operation; -use crate::store_wrapper::StoreWrapper; + use crate::view; use std::path::PathBuf; use std::sync::Arc; +use crate::repo::RepoLoader; use crate::store::CommitId; use std::collections::HashSet; use thiserror::Error; @@ -107,9 +108,7 @@ impl OpHeadsStore { // pass around OperationId and Operation separately like we do here. pub fn get_single_op_head( &self, - store: &StoreWrapper, - op_store: &Arc, - index_store: &Arc, + repo_loader: &RepoLoader, ) -> Result<(OperationId, op_store::Operation, op_store::View), OpHeadResolutionError> { let mut op_heads = self.get_op_heads(); @@ -117,6 +116,7 @@ impl OpHeadsStore { return Err(OpHeadResolutionError::NoHeads); } + let op_store = repo_loader.op_store(); if op_heads.len() == 1 { let operation_id = op_heads.pop().unwrap(); let operation = op_store.read_operation(&operation_id).unwrap(); @@ -157,7 +157,7 @@ impl OpHeadsStore { let op_heads = self.handle_ancestor_ops(op_heads); let (merge_operation_id, merge_operation, merged_view) = - merge_op_heads(store, op_store, index_store, op_heads)?; + merge_op_heads(repo_loader, op_heads)?; self.add_op_head(&merge_operation_id); for old_op_head_id in &merge_operation.parents { self.remove_op_head(old_op_head_id); @@ -184,13 +184,12 @@ impl OpHeadsStore { } fn merge_op_heads( - store: &StoreWrapper, - op_store: &Arc, - index_store: &Arc, + repo_loader: &RepoLoader, mut op_heads: Vec, ) -> Result<(OperationId, op_store::Operation, op_store::View), OpHeadResolutionError> { op_heads.sort_by_key(|op| op.store_operation().metadata.end_time.timestamp.clone()); let first_op_head = op_heads[0].clone(); + let op_store = repo_loader.op_store(); let mut merged_view = op_store.read_view(first_op_head.view().id()).unwrap(); // Return without creating a merge operation @@ -203,6 +202,8 @@ fn merge_op_heads( } let neighbors_fn = |op: &Operation| op.parents(); + let store = repo_loader.store(); + let index_store = repo_loader.index_store(); let base_index = index_store.get_index_at_op(&first_op_head, store); let mut index = MutableIndex::incremental(base_index); for (i, other_op_head) in op_heads.iter().enumerate().skip(1) { diff --git a/lib/src/repo.rs b/lib/src/repo.rs index 336b7b5c9..5b2a3e951 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -345,9 +345,18 @@ impl ReadonlyRepo { } pub fn reload(&mut self) { + let repo_loader = RepoLoader { + wc_path: self.working_copy_path().clone(), + repo_path: self.repo_path.clone(), + repo_settings: self.settings.clone(), + store: self.store.clone(), + op_store: self.op_store.clone(), + op_heads_store: self.op_heads_store.clone(), + index_store: self.index_store.clone(), + }; let (op_id, _operation, op_store_view) = self .op_heads_store - .get_single_op_head(&self.store, &self.op_store, &self.index_store) + .get_single_op_head(&repo_loader) .unwrap(); self.view = ReadonlyView::new( self.store.clone(), @@ -435,15 +444,21 @@ impl RepoLoader { StoreWrapper::new(store) } + pub fn store(&self) -> &Arc { + &self.store + } + + pub fn index_store(&self) -> &Arc { + &self.index_store + } + pub fn op_store(&self) -> &Arc { &self.op_store } pub fn load_at_head(self) -> Result, RepoLoadError> { - let (op_id, _operation, op_store_view) = self - .op_heads_store - .get_single_op_head(&self.store, &self.op_store, &self.index_store) - .unwrap(); + let (op_id, _operation, op_store_view) = + self.op_heads_store.get_single_op_head(&self).unwrap(); let view = ReadonlyView::new( self.store.clone(), self.op_store.clone(),