mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-18 02:04:19 +00:00
view: let repo create OpHeadsStore and pass in to view
This commit is contained in:
parent
ec07104126
commit
212dd35d01
4 changed files with 26 additions and 24 deletions
|
@ -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<dyn OpStore> = 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<StoreWrapper>,
|
||||
op_store: Arc<dyn OpStore>,
|
||||
op_heads_store: Arc<OpHeadsStore>,
|
||||
index_store: Arc<IndexStore>,
|
||||
}
|
||||
|
||||
|
@ -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<dyn OpStore> = 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)
|
||||
|
|
|
@ -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<StoreWrapper>,
|
||||
op_store: Arc<dyn OpStore>,
|
||||
op_heads_store: Arc<OpHeadsStore>,
|
||||
index_store: Arc<IndexStore>,
|
||||
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<StoreWrapper>,
|
||||
op_store: Arc<dyn OpStore>,
|
||||
op_heads_store: Arc<OpHeadsStore>,
|
||||
index_store: Arc<IndexStore>,
|
||||
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<StoreWrapper>,
|
||||
op_store: Arc<dyn OpStore>,
|
||||
op_heads_store: Arc<OpHeadsStore>,
|
||||
index_store: Arc<IndexStore>,
|
||||
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,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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()]);
|
||||
|
||||
|
|
Loading…
Reference in a new issue