mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-18 02:04:19 +00:00
repo: let repo types directly have an OpStore
I'd like to make `ReadonlyView` and `MutableView` focused on just the state of the view (i.e. the set of heads, git refs, etc.). The responsibility for managing the `.jj/view/op_heads/` directory should be moved out of it. This prepares for that.
This commit is contained in:
parent
48d7903925
commit
2955bc4a29
5 changed files with 33 additions and 29 deletions
|
@ -77,6 +77,13 @@ impl<'a, 'r> RepoRef<'a, 'r> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn op_store(&self) -> &'a Arc<dyn OpStore> {
|
||||||
|
match self {
|
||||||
|
RepoRef::Readonly(repo) => repo.op_store(),
|
||||||
|
RepoRef::Mutable(repo) => repo.op_store(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn index(&self) -> IndexRef {
|
pub fn index(&self) -> IndexRef {
|
||||||
match self {
|
match self {
|
||||||
RepoRef::Readonly(repo) => IndexRef::Readonly(repo.index()),
|
RepoRef::Readonly(repo) => IndexRef::Readonly(repo.index()),
|
||||||
|
@ -103,6 +110,7 @@ pub struct ReadonlyRepo {
|
||||||
repo_path: PathBuf,
|
repo_path: PathBuf,
|
||||||
wc_path: PathBuf,
|
wc_path: PathBuf,
|
||||||
store: Arc<StoreWrapper>,
|
store: Arc<StoreWrapper>,
|
||||||
|
op_store: Arc<dyn OpStore>,
|
||||||
settings: RepoSettings,
|
settings: RepoSettings,
|
||||||
index_store: Arc<IndexStore>,
|
index_store: Arc<IndexStore>,
|
||||||
index: Mutex<Option<Arc<ReadonlyIndex>>>,
|
index: Mutex<Option<Arc<ReadonlyIndex>>>,
|
||||||
|
@ -208,7 +216,7 @@ impl ReadonlyRepo {
|
||||||
|
|
||||||
let view = ReadonlyView::init(
|
let view = ReadonlyView::init(
|
||||||
store.clone(),
|
store.clone(),
|
||||||
op_store,
|
op_store.clone(),
|
||||||
index_store.clone(),
|
index_store.clone(),
|
||||||
repo_path.join("view"),
|
repo_path.join("view"),
|
||||||
checkout_commit.id().clone(),
|
checkout_commit.id().clone(),
|
||||||
|
@ -218,6 +226,7 @@ impl ReadonlyRepo {
|
||||||
repo_path,
|
repo_path,
|
||||||
wc_path,
|
wc_path,
|
||||||
store,
|
store,
|
||||||
|
op_store,
|
||||||
settings: repo_settings,
|
settings: repo_settings,
|
||||||
index_store,
|
index_store,
|
||||||
index: Mutex::new(None),
|
index: Mutex::new(None),
|
||||||
|
@ -278,8 +287,8 @@ impl ReadonlyRepo {
|
||||||
let mut locked_index = self.index.lock().unwrap();
|
let mut locked_index = self.index.lock().unwrap();
|
||||||
if locked_index.is_none() {
|
if locked_index.is_none() {
|
||||||
let op_id = self.view.op_id().clone();
|
let op_id = self.view.op_id().clone();
|
||||||
let op = self.view.op_store().read_operation(&op_id).unwrap();
|
let op = self.op_store.read_operation(&op_id).unwrap();
|
||||||
let op = Operation::new(self.view.op_store().clone(), op_id, op);
|
let op = Operation::new(self.op_store.clone(), op_id, op);
|
||||||
locked_index.replace(self.index_store.get_index_at_op(&op, self.store.as_ref()));
|
locked_index.replace(self.index_store.get_index_at_op(&op, self.store.as_ref()));
|
||||||
}
|
}
|
||||||
locked_index.as_ref().unwrap().clone()
|
locked_index.as_ref().unwrap().clone()
|
||||||
|
@ -306,6 +315,10 @@ impl ReadonlyRepo {
|
||||||
&self.store
|
&self.store
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn op_store(&self) -> &Arc<dyn OpStore> {
|
||||||
|
&self.op_store
|
||||||
|
}
|
||||||
|
|
||||||
pub fn index_store(&self) -> &Arc<IndexStore> {
|
pub fn index_store(&self) -> &Arc<IndexStore> {
|
||||||
&self.index_store
|
&self.index_store
|
||||||
}
|
}
|
||||||
|
@ -433,6 +446,7 @@ impl RepoLoader {
|
||||||
repo_path: self.repo_path,
|
repo_path: self.repo_path,
|
||||||
wc_path: self.wc_path,
|
wc_path: self.wc_path,
|
||||||
store: self.store,
|
store: self.store,
|
||||||
|
op_store: self.op_store,
|
||||||
settings: self.repo_settings,
|
settings: self.repo_settings,
|
||||||
index_store: self.index_store,
|
index_store: self.index_store,
|
||||||
index: Mutex::new(None),
|
index: Mutex::new(None),
|
||||||
|
@ -485,16 +499,20 @@ impl<'r> MutableRepo<'r> {
|
||||||
RepoRef::Mutable(&self)
|
RepoRef::Mutable(&self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn base_repo(&self) -> &'r ReadonlyRepo {
|
||||||
|
self.repo
|
||||||
|
}
|
||||||
|
|
||||||
pub fn store(&self) -> &Arc<StoreWrapper> {
|
pub fn store(&self) -> &Arc<StoreWrapper> {
|
||||||
self.repo.store()
|
self.repo.store()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn index(&self) -> &MutableIndex {
|
pub fn op_store(&self) -> &Arc<dyn OpStore> {
|
||||||
&self.index
|
self.repo.op_store()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn base_repo(&self) -> &'r ReadonlyRepo {
|
pub fn index(&self) -> &MutableIndex {
|
||||||
self.repo
|
&self.index
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&self) -> &MutableView {
|
pub fn view(&self) -> &MutableView {
|
||||||
|
|
|
@ -36,7 +36,6 @@ pub enum ViewRef<'a> {
|
||||||
Mutable(&'a MutableView),
|
Mutable(&'a MutableView),
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Move OpStore out of View?
|
|
||||||
impl<'a> ViewRef<'a> {
|
impl<'a> ViewRef<'a> {
|
||||||
pub fn checkout(&self) -> &'a CommitId {
|
pub fn checkout(&self) -> &'a CommitId {
|
||||||
match self {
|
match self {
|
||||||
|
@ -66,10 +65,10 @@ impl<'a> ViewRef<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn op_store(&self) -> Arc<dyn OpStore> {
|
fn op_store(&self) -> &Arc<dyn OpStore> {
|
||||||
match self {
|
match self {
|
||||||
ViewRef::Readonly(view) => view.op_store(),
|
ViewRef::Readonly(view) => &view.op_store,
|
||||||
ViewRef::Mutable(view) => view.op_store(),
|
ViewRef::Mutable(view) => &view.op_store,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +79,7 @@ impl<'a> ViewRef<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_operation(&self, id: &OperationId) -> OpStoreResult<Operation> {
|
fn get_operation(&self, id: &OperationId) -> OpStoreResult<Operation> {
|
||||||
let data = self.op_store().read_operation(id)?;
|
let data = self.op_store().read_operation(id)?;
|
||||||
Ok(Operation::new(self.op_store().clone(), id.clone(), data))
|
Ok(Operation::new(self.op_store().clone(), id.clone(), data))
|
||||||
}
|
}
|
||||||
|
@ -490,10 +489,6 @@ impl ReadonlyView {
|
||||||
&self.data.git_refs
|
&self.data.git_refs
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn op_store(&self) -> Arc<dyn OpStore> {
|
|
||||||
self.op_store.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn op_id(&self) -> &OperationId {
|
pub fn op_id(&self) -> &OperationId {
|
||||||
&self.op_id
|
&self.op_id
|
||||||
}
|
}
|
||||||
|
@ -520,10 +515,6 @@ impl MutableView {
|
||||||
&self.data.git_refs
|
&self.data.git_refs
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn op_store(&self) -> Arc<dyn OpStore> {
|
|
||||||
self.op_store.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn base_op_id(&self) -> &OperationId {
|
pub fn base_op_id(&self) -> &OperationId {
|
||||||
&self.base_op_id
|
&self.base_op_id
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,11 +131,7 @@ fn test_bad_locking_children(use_git: bool) {
|
||||||
assert!(merged_repo.view().heads().contains(child1.id()));
|
assert!(merged_repo.view().heads().contains(child1.id()));
|
||||||
assert!(merged_repo.view().heads().contains(child2.id()));
|
assert!(merged_repo.view().heads().contains(child2.id()));
|
||||||
let op_id = merged_repo.view().op_id().clone();
|
let op_id = merged_repo.view().op_id().clone();
|
||||||
let op = merged_repo
|
let op = merged_repo.op_store().read_operation(&op_id).unwrap();
|
||||||
.view()
|
|
||||||
.op_store()
|
|
||||||
.read_operation(&op_id)
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(op.parents.len(), 2);
|
assert_eq!(op.parents.len(), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,9 +21,8 @@ use std::sync::Arc;
|
||||||
use test_case::test_case;
|
use test_case::test_case;
|
||||||
|
|
||||||
fn count_non_merge_operations(repo: &ReadonlyRepo) -> u32 {
|
fn count_non_merge_operations(repo: &ReadonlyRepo) -> u32 {
|
||||||
let view = repo.view();
|
let op_store = repo.op_store();
|
||||||
let op_store = view.op_store();
|
let op_id = repo.view().op_id().clone();
|
||||||
let op_id = view.op_id().clone();
|
|
||||||
let mut num_ops = 0;
|
let mut num_ops = 0;
|
||||||
|
|
||||||
for op_id in dag_walk::bfs(
|
for op_id in dag_walk::bfs(
|
||||||
|
|
|
@ -207,7 +207,7 @@ fn resolve_single_op(repo: &ReadonlyRepo, op_str: &str) -> Result<Operation, Com
|
||||||
if op_str == "@" {
|
if op_str == "@" {
|
||||||
Ok(view.as_view_ref().base_op())
|
Ok(view.as_view_ref().base_op())
|
||||||
} else {
|
} else {
|
||||||
resolve_single_op_from_store(&repo.view().op_store(), op_str)
|
resolve_single_op_from_store(&repo.op_store(), op_str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue