diff --git a/lib/src/repo.rs b/lib/src/repo.rs index dccc46528..362ba4f0f 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -30,6 +30,7 @@ use crate::git_store::GitStore; use crate::index::{IndexRef, MutableIndex, ReadonlyIndex}; use crate::index_store::IndexStore; use crate::local_store::LocalStore; +use crate::op_heads_store::OpHeadsStore; use crate::op_store; use crate::op_store::OpStore; use crate::operation::Operation; @@ -211,15 +212,22 @@ impl ReadonlyRepo { std::fs::create_dir(repo_path.join("op_store")).unwrap(); let op_store: Arc = Arc::new(SimpleOpStore::init(repo_path.join("op_store"))); + let op_heads_dir = repo_path.join("op_heads"); + std::fs::create_dir(&op_heads_dir).unwrap(); + let (op_heads_store, init_op_id, root_view) = + OpHeadsStore::init(op_heads_dir, &op_store, checkout_commit.id().clone()); + let op_heads_store = Arc::new(op_heads_store); + 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, index_store.clone(), - repo_path.join("view"), - checkout_commit.id().clone(), + init_op_id, + root_view, ); let repo = ReadonlyRepo { @@ -366,6 +374,7 @@ pub struct RepoLoader { repo_settings: RepoSettings, store: Arc, op_store: Arc, + op_heads_store: Arc, index_store: Arc, } @@ -379,6 +388,7 @@ impl RepoLoader { let store = RepoLoader::load_store(&repo_path); let repo_settings = user_settings.with_repo(&repo_path).unwrap(); let op_store: Arc = Arc::new(SimpleOpStore::load(repo_path.join("op_store"))); + let op_heads_store = Arc::new(OpHeadsStore::load(repo_path.join("op_heads"))); let index_store = Arc::new(IndexStore::load(repo_path.join("index"))); Ok(RepoLoader { wc_path, @@ -386,6 +396,7 @@ impl RepoLoader { repo_settings, store, op_store, + op_heads_store, index_store, }) } @@ -419,8 +430,8 @@ impl RepoLoader { let view = ReadonlyView::load( self.store.clone(), self.op_store.clone(), + self.op_heads_store.clone(), self.index_store.clone(), - self.repo_path.join("view"), ); self._finish_load(view) } @@ -429,8 +440,8 @@ impl RepoLoader { let view = ReadonlyView::load_at( self.store.clone(), self.op_store.clone(), + self.op_heads_store.clone(), self.index_store.clone(), - self.repo_path.join("view"), op, ); self._finish_load(view) diff --git a/lib/src/view.rs b/lib/src/view.rs index 2e0a0c443..0e669afb9 100644 --- a/lib/src/view.rs +++ b/lib/src/view.rs @@ -14,7 +14,6 @@ use std::cmp::min; use std::collections::{BTreeMap, HashSet}; -use std::path::PathBuf; use std::sync::Arc; use crate::commit::Commit; @@ -215,19 +214,15 @@ impl ReadonlyView { pub fn init( store: Arc, op_store: Arc, + op_heads_store: Arc, index_store: Arc, - path: PathBuf, - checkout: CommitId, + init_op_id: OperationId, + root_view: op_store::View, ) -> Self { - let op_heads_dir = path.join("op_heads"); - std::fs::create_dir(&op_heads_dir).unwrap(); - let (op_heads_store, init_op_id, root_view) = - OpHeadsStore::init(op_heads_dir, &op_store, checkout); - ReadonlyView { store, op_store, - op_heads_store: Arc::new(op_heads_store), + op_heads_store, op_id: init_op_id, index_store, data: root_view, @@ -237,11 +232,9 @@ impl ReadonlyView { pub fn load( store: Arc, op_store: Arc, + op_heads_store: Arc, index_store: Arc, - path: PathBuf, ) -> Self { - let op_heads_dir = path.join("op_heads"); - let op_heads_store = Arc::new(OpHeadsStore::load(op_heads_dir)); let (op_id, _operation, view) = op_heads_store .get_single_op_head(&store, &op_store, &index_store) .unwrap(); @@ -258,12 +251,10 @@ impl ReadonlyView { pub fn load_at( store: Arc, op_store: Arc, + op_heads_store: Arc, index_store: Arc, - path: PathBuf, operation: &Operation, ) -> Self { - let op_heads_dir = path.join("op_heads"); - let op_heads_store = Arc::new(OpHeadsStore::load(op_heads_dir)); ReadonlyView { store, op_store, diff --git a/lib/tests/test_bad_locking.rs b/lib/tests/test_bad_locking.rs index 377d10a9e..a1f3d780d 100644 --- a/lib/tests/test_bad_locking.rs +++ b/lib/tests/test_bad_locking.rs @@ -150,10 +150,10 @@ fn test_bad_locking_interrupted(use_git: bool) { Arc::get_mut(&mut repo).unwrap().reload(); // Simulate a crash that resulted in the old op-head left in place. We simulate - // it somewhat hackily by copying the view/op_heads/ directory before the + // it somewhat hackily by copying the .jj/op_heads/ directory before the // operation and then copying that back afterwards, leaving the existing // op-head(s) in place. - let op_heads_dir = repo.repo_path().join("view").join("op_heads"); + let op_heads_dir = repo.repo_path().join("op_heads"); let backup_path = TempDir::new().unwrap().into_path(); copy_directory(&op_heads_dir, &backup_path); let mut tx = repo.start_transaction("test"); @@ -166,7 +166,7 @@ fn test_bad_locking_interrupted(use_git: bool) { // Reload the repo and check that only the new head is present. let reloaded_repo = ReadonlyRepo::load(&settings, repo.working_copy_path().clone()).unwrap(); assert_eq!(reloaded_repo.view().op_id(), &op_id); - // Reload once more to make sure that the view/op_heads/ directory was updated + // Reload once more to make sure that the .jj/op_heads/ directory was updated // correctly. let reloaded_repo = ReadonlyRepo::load(&settings, repo.working_copy_path().clone()).unwrap(); assert_eq!(reloaded_repo.view().op_id(), &op_id); diff --git a/lib/tests/test_operations.rs b/lib/tests/test_operations.rs index a8b7bb8e7..c18f22711 100644 --- a/lib/tests/test_operations.rs +++ b/lib/tests/test_operations.rs @@ -35,7 +35,7 @@ fn test_consecutive_operations(use_git: bool) { let settings = testutils::user_settings(); let (_temp_dir, mut repo) = testutils::init_repo(&settings, use_git); - let op_heads_dir = repo.repo_path().join("view").join("op_heads"); + let op_heads_dir = repo.repo_path().join("op_heads"); let op_id0 = repo.view().op_id().clone(); assert_eq!(list_dir(&op_heads_dir), vec![repo.view().op_id().hex()]); @@ -67,7 +67,7 @@ fn test_concurrent_operations(use_git: bool) { let settings = testutils::user_settings(); let (_temp_dir, mut repo) = testutils::init_repo(&settings, use_git); - let op_heads_dir = repo.repo_path().join("view").join("op_heads"); + let op_heads_dir = repo.repo_path().join("op_heads"); let op_id0 = repo.view().op_id().clone(); assert_eq!(list_dir(&op_heads_dir), vec![repo.view().op_id().hex()]);