forked from mirrors/jj
view: let repo get current operation from OpHeadsStore and pass in
This makes the View types a lot simpler.
This commit is contained in:
parent
82a3ff6ef8
commit
f79874d612
2 changed files with 31 additions and 81 deletions
|
@ -222,14 +222,7 @@ impl ReadonlyRepo {
|
|||
fs::create_dir(repo_path.join("index")).unwrap();
|
||||
let index_store = Arc::new(IndexStore::init(repo_path.join("index")));
|
||||
|
||||
let view = ReadonlyView::init(
|
||||
store.clone(),
|
||||
op_store.clone(),
|
||||
op_heads_store.clone(),
|
||||
index_store.clone(),
|
||||
init_op_id,
|
||||
root_view,
|
||||
);
|
||||
let view = ReadonlyView::new(store.clone(), op_store.clone(), init_op_id, root_view);
|
||||
|
||||
let repo = ReadonlyRepo {
|
||||
repo_path,
|
||||
|
@ -352,7 +345,16 @@ impl ReadonlyRepo {
|
|||
}
|
||||
|
||||
pub fn reload(&mut self) {
|
||||
self.view.reload();
|
||||
let (op_id, _operation, op_store_view) = self
|
||||
.op_heads_store
|
||||
.get_single_op_head(&self.store, &self.op_store, &self.index_store)
|
||||
.unwrap();
|
||||
self.view = ReadonlyView::new(
|
||||
self.store.clone(),
|
||||
self.op_store.clone(),
|
||||
op_id,
|
||||
op_store_view,
|
||||
);
|
||||
let repo_ref: &ReadonlyRepo = self;
|
||||
let static_lifetime_repo: &'static ReadonlyRepo = unsafe { std::mem::transmute(repo_ref) };
|
||||
{
|
||||
|
@ -363,7 +365,12 @@ impl ReadonlyRepo {
|
|||
}
|
||||
|
||||
pub fn reload_at(&mut self, operation: &Operation) {
|
||||
self.view.reload_at(operation);
|
||||
self.view = ReadonlyView::new(
|
||||
self.store.clone(),
|
||||
self.op_store.clone(),
|
||||
operation.id().clone(),
|
||||
operation.view().take_store_view(),
|
||||
);
|
||||
let repo_ref: &ReadonlyRepo = self;
|
||||
let static_lifetime_repo: &'static ReadonlyRepo = unsafe { std::mem::transmute(repo_ref) };
|
||||
{
|
||||
|
@ -433,22 +440,25 @@ impl RepoLoader {
|
|||
}
|
||||
|
||||
pub fn load_at_head(self) -> Result<Arc<ReadonlyRepo>, RepoLoadError> {
|
||||
let view = ReadonlyView::load(
|
||||
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 view = ReadonlyView::new(
|
||||
self.store.clone(),
|
||||
self.op_store.clone(),
|
||||
self.op_heads_store.clone(),
|
||||
self.index_store.clone(),
|
||||
op_id,
|
||||
op_store_view,
|
||||
);
|
||||
self._finish_load(view)
|
||||
}
|
||||
|
||||
pub fn load_at(self, op: &Operation) -> Result<Arc<ReadonlyRepo>, RepoLoadError> {
|
||||
let view = ReadonlyView::load_at(
|
||||
let view = ReadonlyView::new(
|
||||
self.store.clone(),
|
||||
self.op_store.clone(),
|
||||
self.op_heads_store.clone(),
|
||||
self.index_store.clone(),
|
||||
op,
|
||||
op.id().clone(),
|
||||
op.view().take_store_view(),
|
||||
);
|
||||
self._finish_load(view)
|
||||
}
|
||||
|
|
|
@ -17,8 +17,6 @@ use std::collections::{BTreeMap, HashSet};
|
|||
use std::sync::Arc;
|
||||
|
||||
use crate::commit::Commit;
|
||||
use crate::index_store::IndexStore;
|
||||
use crate::op_heads_store::OpHeadsStore;
|
||||
use crate::op_store;
|
||||
use crate::op_store::{OpStore, OpStoreResult, OperationId, OperationMetadata};
|
||||
use crate::operation::Operation;
|
||||
|
@ -86,9 +84,7 @@ impl<'a> ViewRef<'a> {
|
|||
pub struct ReadonlyView {
|
||||
store: Arc<StoreWrapper>,
|
||||
op_store: Arc<dyn OpStore>,
|
||||
op_heads_store: Arc<OpHeadsStore>,
|
||||
op_id: OperationId,
|
||||
index_store: Arc<IndexStore>,
|
||||
data: op_store::View,
|
||||
}
|
||||
|
||||
|
@ -210,76 +206,20 @@ pub fn merge_views(
|
|||
}
|
||||
|
||||
impl ReadonlyView {
|
||||
pub fn init(
|
||||
pub fn new(
|
||||
store: Arc<StoreWrapper>,
|
||||
op_store: Arc<dyn OpStore>,
|
||||
op_heads_store: Arc<OpHeadsStore>,
|
||||
index_store: Arc<IndexStore>,
|
||||
init_op_id: OperationId,
|
||||
root_view: op_store::View,
|
||||
op_id: OperationId,
|
||||
op_store_view: op_store::View,
|
||||
) -> Self {
|
||||
ReadonlyView {
|
||||
store,
|
||||
op_store,
|
||||
op_heads_store,
|
||||
op_id: init_op_id,
|
||||
index_store,
|
||||
data: root_view,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load(
|
||||
store: Arc<StoreWrapper>,
|
||||
op_store: Arc<dyn OpStore>,
|
||||
op_heads_store: Arc<OpHeadsStore>,
|
||||
index_store: Arc<IndexStore>,
|
||||
) -> Self {
|
||||
// TODO: We should probably move this get_single_op_head() call to ReadonlyRepo.
|
||||
let (op_id, _operation, view) = op_heads_store
|
||||
.get_single_op_head(&store, &op_store, &index_store)
|
||||
.unwrap();
|
||||
ReadonlyView {
|
||||
store,
|
||||
op_store,
|
||||
op_heads_store,
|
||||
op_id,
|
||||
index_store,
|
||||
data: view,
|
||||
data: op_store_view,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_at(
|
||||
store: Arc<StoreWrapper>,
|
||||
op_store: Arc<dyn OpStore>,
|
||||
op_heads_store: Arc<OpHeadsStore>,
|
||||
index_store: Arc<IndexStore>,
|
||||
operation: &Operation,
|
||||
) -> Self {
|
||||
ReadonlyView {
|
||||
store,
|
||||
op_store,
|
||||
op_heads_store,
|
||||
op_id: operation.id().clone(),
|
||||
index_store,
|
||||
data: operation.view().take_store_view(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn reload(&mut self) -> OperationId {
|
||||
let (op_id, _operation, view) = self
|
||||
.op_heads_store
|
||||
.get_single_op_head(&self.store, &self.op_store, &self.index_store)
|
||||
.unwrap();
|
||||
self.op_id = op_id;
|
||||
self.data = view;
|
||||
self.op_id.clone()
|
||||
}
|
||||
|
||||
pub fn reload_at(&mut self, operation: &Operation) {
|
||||
self.op_id = operation.id().clone();
|
||||
self.data = operation.view().take_store_view();
|
||||
}
|
||||
|
||||
pub fn start_modification(&self) -> MutableView {
|
||||
// TODO: Avoid the cloning of the sets here.
|
||||
MutableView {
|
||||
|
|
Loading…
Reference in a new issue