ok/jj
1
0
Fork 0
forked from mirrors/jj

view: move creation of initial operation to OpHeadsStore

This is a step towards getting rid of
`MutableView::update_op_heads()`.
This commit is contained in:
Martin von Zweigbergk 2021-03-10 22:45:56 -08:00
parent 2590e127f7
commit ec07104126
2 changed files with 24 additions and 17 deletions

View file

@ -24,6 +24,7 @@ use crate::view;
use std::path::PathBuf;
use std::sync::Arc;
use crate::store::CommitId;
use thiserror::Error;
/// Manages the very set of current heads of the operation log. The store is
@ -40,8 +41,25 @@ pub enum OpHeadResolutionError {
}
impl OpHeadsStore {
pub fn init(dir: PathBuf) -> Self {
OpHeadsStore { dir }
pub fn init(
dir: PathBuf,
op_store: &Arc<dyn OpStore>,
checkout: CommitId,
) -> (Self, OperationId, op_store::View) {
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();
let operation_metadata = OperationMetadata::new("initialize repo".to_string());
let init_operation = op_store::Operation {
view_id: root_view_id,
parents: vec![],
metadata: operation_metadata,
};
let init_operation_id = op_store.write_operation(&init_operation).unwrap();
let op_heads_store = OpHeadsStore { dir };
op_heads_store.add_op_head(&init_operation_id);
(op_heads_store, init_operation_id, root_view)
}
pub fn load(dir: PathBuf) -> OpHeadsStore {

View file

@ -219,27 +219,16 @@ impl ReadonlyView {
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();
let operation_metadata = OperationMetadata::new("initialize repo".to_string());
let init_operation = op_store::Operation {
view_id: root_view_id,
parents: vec![],
metadata: operation_metadata,
};
let init_operation_id = op_store.write_operation(&init_operation).unwrap();
let op_heads_dir = path.join("op_heads");
std::fs::create_dir(&op_heads_dir).unwrap();
let op_heads_store = Arc::new(OpHeadsStore::init(op_heads_dir));
op_heads_store.add_op_head(&init_operation_id);
let (op_heads_store, init_op_id, root_view) =
OpHeadsStore::init(op_heads_dir, &op_store, checkout);
ReadonlyView {
store,
op_store,
op_heads_store,
op_id: init_operation_id,
op_heads_store: Arc::new(op_heads_store),
op_id: init_op_id,
index_store,
data: root_view,
}