From 5a32118af1ff3e44c7aa8acbb6cc7ade04d0ac07 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Fri, 26 Feb 2021 23:37:42 -0800 Subject: [PATCH] repo: move creation of OpStore out of View We want to support loading the repo at a specific operation without first loading the head operation (like we currently do). One reason for that is of course efficiency. A possibly more important reason is that the head operation may be conflicted, depending on how we decide to deal with operation-level conflicts. In order to do that, it makes sense to move the creation of the `OpStore` outside of the `View`. That also suggests that the `.jj/view/op_store/` directory should move to `.jj/op_store/`, so this patch also does that. That's consistent with how `.jj/store/` is outside of `.jj/working_copy/`. --- lib/src/repo.rs | 9 ++++++++- lib/src/view.rs | 14 +++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/src/repo.rs b/lib/src/repo.rs index 3995d207a..dde5180f0 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -26,8 +26,10 @@ use crate::evolution::{EvolutionRef, MutableEvolution, ReadonlyEvolution}; use crate::git_store::GitStore; use crate::index::{IndexRef, MutableIndex, ReadonlyIndex}; use crate::local_store::LocalStore; +use crate::op_store::OpStore; use crate::operation::Operation; use crate::settings::{RepoSettings, UserSettings}; +use crate::simple_op_store::SimpleOpStore; use crate::store; use crate::store::{Store, StoreError}; use crate::store_wrapper::StoreWrapper; @@ -191,8 +193,12 @@ impl ReadonlyRepo { is_pruned: false, }; let checkout_commit = store.write_commit(checkout_commit); + + std::fs::create_dir(repo_path.join("op_store")).unwrap(); + let op_store: Arc = Arc::new(SimpleOpStore::init(repo_path.join("op_store"))); let view = ReadonlyView::init( store.clone(), + op_store, repo_path.join("view"), checkout_commit.id().clone(), ); @@ -254,7 +260,8 @@ impl ReadonlyRepo { wc_path.clone(), repo_path.join("working_copy"), ); - let view = ReadonlyView::load(store.clone(), repo_path.join("view")); + let op_store: Arc = Arc::new(SimpleOpStore::load(repo_path.join("op_store"))); + let view = ReadonlyView::load(store.clone(), op_store, repo_path.join("view")); let repo = ReadonlyRepo { repo_path, wc_path, diff --git a/lib/src/view.rs b/lib/src/view.rs index 0c0cf3ffd..430ac1fdd 100644 --- a/lib/src/view.rs +++ b/lib/src/view.rs @@ -26,7 +26,6 @@ use crate::lock::FileLock; use crate::op_store; use crate::op_store::{OpStore, OpStoreResult, OperationId, OperationMetadata}; use crate::operation::Operation; -use crate::simple_op_store::SimpleOpStore; use crate::store::{CommitId, Timestamp}; use crate::store_wrapper::StoreWrapper; @@ -361,10 +360,12 @@ fn merge_op_heads( } impl ReadonlyView { - pub fn init(store: Arc, path: PathBuf, checkout: CommitId) -> Self { - std::fs::create_dir(path.join("op_store")).unwrap(); - - let op_store = Arc::new(SimpleOpStore::init(path.join("op_store"))); + pub fn init( + store: Arc, + op_store: Arc, + path: PathBuf, + checkout: CommitId, + ) -> Self { let mut root_view = op_store::View::new(checkout.clone()); root_view.head_ids.insert(checkout); let root_view_id = op_store.write_view(&root_view).unwrap(); @@ -389,8 +390,7 @@ impl ReadonlyView { } } - pub fn load(store: Arc, path: PathBuf) -> Self { - let op_store: Arc = Arc::new(SimpleOpStore::load(path.join("op_store"))); + pub fn load(store: Arc, op_store: Arc, path: PathBuf) -> Self { let op_heads_dir = path.join("op_heads"); let (op_id, _operation, view) = get_single_op_head(&store, &op_store, &op_heads_dir).unwrap();