mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-18 18:27:38 +00:00
View: move creation of Operation to Transaction
This continues the work to make the `View` types be only about the state of the current view and not about operations in general (which has been moved out `OpStore` and qOpHeadsStore`).
This commit is contained in:
parent
cf2baf58a7
commit
c1de8b0f3a
4 changed files with 25 additions and 24 deletions
|
@ -25,7 +25,7 @@ use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::repo::RepoLoader;
|
use crate::repo::RepoLoader;
|
||||||
use crate::store::CommitId;
|
use crate::store::{CommitId, Timestamp};
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ impl OpHeadsStore {
|
||||||
let mut root_view = op_store::View::new(checkout.clone());
|
let mut root_view = op_store::View::new(checkout.clone());
|
||||||
root_view.head_ids.insert(checkout);
|
root_view.head_ids.insert(checkout);
|
||||||
let root_view_id = op_store.write_view(&root_view).unwrap();
|
let root_view_id = op_store.write_view(&root_view).unwrap();
|
||||||
let operation_metadata = OperationMetadata::new("initialize repo".to_string());
|
let operation_metadata = OperationMetadata::new("initialize repo".to_string(), Timestamp::now());
|
||||||
let init_operation = op_store::Operation {
|
let init_operation = op_store::Operation {
|
||||||
view_id: root_view_id,
|
view_id: root_view_id,
|
||||||
parents: vec![],
|
parents: vec![],
|
||||||
|
@ -216,7 +216,7 @@ fn merge_op_heads(
|
||||||
}
|
}
|
||||||
let merged_index = index_store.write_index(index).unwrap();
|
let merged_index = index_store.write_index(index).unwrap();
|
||||||
let merged_view_id = op_store.write_view(&merged_view).unwrap();
|
let merged_view_id = op_store.write_view(&merged_view).unwrap();
|
||||||
let operation_metadata = OperationMetadata::new("resolve concurrent operations".to_string());
|
let operation_metadata = OperationMetadata::new("resolve concurrent operations".to_string(), Timestamp::now());
|
||||||
let op_parent_ids = op_heads.iter().map(|op| op.id().clone()).collect();
|
let op_parent_ids = op_heads.iter().map(|op| op.id().clone()).collect();
|
||||||
let merge_operation = op_store::Operation {
|
let merge_operation = op_store::Operation {
|
||||||
view_id: merged_view_id,
|
view_id: merged_view_id,
|
||||||
|
|
|
@ -103,13 +103,13 @@ pub struct OperationMetadata {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OperationMetadata {
|
impl OperationMetadata {
|
||||||
pub fn new(description: String) -> Self {
|
pub fn new(description: String, start_time: Timestamp) -> Self {
|
||||||
let timestamp = Timestamp::now();
|
let end_time = Timestamp::now();
|
||||||
let hostname = whoami::hostname();
|
let hostname = whoami::hostname();
|
||||||
let username = whoami::username();
|
let username = whoami::username();
|
||||||
OperationMetadata {
|
OperationMetadata {
|
||||||
start_time: timestamp.clone(),
|
start_time,
|
||||||
end_time: timestamp,
|
end_time,
|
||||||
description,
|
description,
|
||||||
hostname,
|
hostname,
|
||||||
username,
|
username,
|
||||||
|
|
|
@ -25,6 +25,7 @@ use crate::store::{CommitId, Timestamp};
|
||||||
use crate::store_wrapper::StoreWrapper;
|
use crate::store_wrapper::StoreWrapper;
|
||||||
use crate::view::MutableView;
|
use crate::view::MutableView;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use crate::op_store::OperationMetadata;
|
||||||
|
|
||||||
pub struct Transaction<'r> {
|
pub struct Transaction<'r> {
|
||||||
repo: Option<Arc<MutableRepo<'r>>>,
|
repo: Option<Arc<MutableRepo<'r>>>,
|
||||||
|
@ -132,11 +133,20 @@ impl<'r> Transaction<'r> {
|
||||||
pub fn write(mut self) -> UnpublishedOperation {
|
pub fn write(mut self) -> UnpublishedOperation {
|
||||||
let mut_repo = Arc::try_unwrap(self.repo.take().unwrap()).ok().unwrap();
|
let mut_repo = Arc::try_unwrap(self.repo.take().unwrap()).ok().unwrap();
|
||||||
let base_repo = mut_repo.base_repo();
|
let base_repo = mut_repo.base_repo();
|
||||||
let index_store = base_repo.index_store();
|
|
||||||
let (mut_index, mut_view) = mut_repo.consume();
|
let (mut_index, mut_view) = mut_repo.consume();
|
||||||
let index = index_store.write_index(mut_index).unwrap();
|
let index = base_repo.index_store().write_index(mut_index).unwrap();
|
||||||
let operation = mut_view.save(self.description.clone(), self.start_time.clone());
|
|
||||||
index_store
|
let view_id = base_repo.op_store().write_view(mut_view.store_view()).unwrap();
|
||||||
|
let operation_metadata = OperationMetadata::new(self.description.clone(),self.start_time.clone());
|
||||||
|
let store_operation = op_store::Operation {
|
||||||
|
view_id,
|
||||||
|
parents: vec![base_repo.view().op_id().clone()],
|
||||||
|
metadata: operation_metadata,
|
||||||
|
};
|
||||||
|
let new_op_id = base_repo.op_store().write_operation(&store_operation).unwrap();
|
||||||
|
let operation = Operation::new(base_repo.op_store().clone(), new_op_id, store_operation);
|
||||||
|
|
||||||
|
base_repo.index_store()
|
||||||
.associate_file_with_operation(&index, operation.id())
|
.associate_file_with_operation(&index, operation.id())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
self.closed = true;
|
self.closed = true;
|
||||||
|
|
|
@ -18,9 +18,9 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use crate::commit::Commit;
|
use crate::commit::Commit;
|
||||||
use crate::op_store;
|
use crate::op_store;
|
||||||
use crate::op_store::{OpStore, OpStoreResult, OperationId, OperationMetadata};
|
use crate::op_store::{OpStore, OpStoreResult, OperationId};
|
||||||
use crate::operation::Operation;
|
use crate::operation::Operation;
|
||||||
use crate::store::{CommitId, Timestamp};
|
use crate::store::{CommitId};
|
||||||
use crate::store_wrapper::StoreWrapper;
|
use crate::store_wrapper::StoreWrapper;
|
||||||
|
|
||||||
pub enum ViewRef<'a> {
|
pub enum ViewRef<'a> {
|
||||||
|
@ -319,16 +319,7 @@ impl MutableView {
|
||||||
enforce_invariants(&self.store, &mut self.data);
|
enforce_invariants(&self.store, &mut self.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn save(&self, description: String, operation_start_time: Timestamp) -> Operation {
|
pub fn store_view(&self) -> &op_store::View {
|
||||||
let view_id = self.op_store.write_view(&self.data).unwrap();
|
&self.data
|
||||||
let mut operation_metadata = OperationMetadata::new(description);
|
|
||||||
operation_metadata.start_time = operation_start_time;
|
|
||||||
let operation = op_store::Operation {
|
|
||||||
view_id,
|
|
||||||
parents: vec![self.base_op_id.clone()],
|
|
||||||
metadata: operation_metadata,
|
|
||||||
};
|
|
||||||
let new_op_id = self.op_store.write_operation(&operation).unwrap();
|
|
||||||
Operation::new(self.op_store.clone(), new_op_id, operation)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue