diff --git a/lib/src/repo.rs b/lib/src/repo.rs index 4a2e70220..78eea52cf 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -24,7 +24,7 @@ use once_cell::sync::OnceCell; use thiserror::Error; use self::dirty_cell::DirtyCell; -use crate::backend::{Backend, BackendError, ChangeId, CommitId, Timestamp}; +use crate::backend::{Backend, BackendError, ChangeId, CommitId}; use crate::commit::Commit; use crate::commit_builder::CommitBuilder; use crate::dag_walk::topo_order_reverse; @@ -137,7 +137,7 @@ impl ReadonlyRepo { let op_heads_path = repo_path.join("op_heads"); fs::create_dir(&op_heads_path).context(&op_heads_path)?; let operation_metadata = - crate::transaction::create_op_metadata(Timestamp::now(), "initialize repo".to_string()); + crate::transaction::create_op_metadata("initialize repo".to_string()); let (op_heads_store, init_op) = OpHeadsStore::init(op_heads_path, &op_store, &root_view, operation_metadata); let op_heads_store = Arc::new(op_heads_store); diff --git a/lib/src/transaction.rs b/lib/src/transaction.rs index acfa1ee05..78be81da1 100644 --- a/lib/src/transaction.rs +++ b/lib/src/transaction.rs @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::collections::HashMap; use std::sync::Arc; use crate::backend::Timestamp; @@ -27,20 +26,17 @@ use crate::view::View; pub struct Transaction { repo: Option, parent_ops: Vec, - description: String, - start_time: Timestamp, - tags: HashMap, + op_metadata: OperationMetadata, } impl Transaction { pub fn new(mut_repo: MutableRepo, description: &str) -> Transaction { let parent_ops = vec![mut_repo.base_repo().operation().clone()]; + let op_metadata = create_op_metadata(description.to_string()); Transaction { repo: Some(mut_repo), parent_ops, - description: description.to_owned(), - start_time: Timestamp::now(), - tags: Default::default(), + op_metadata, } } @@ -49,7 +45,7 @@ impl Transaction { } pub fn set_tag(&mut self, key: String, value: String) { - self.tags.insert(key, value); + self.op_metadata.tags.insert(key, value); } pub fn repo(&self) -> &MutableRepo { @@ -96,14 +92,12 @@ impl Transaction { let index = base_repo.index_store().write_index(mut_index).unwrap(); let view_id = base_repo.op_store().write_view(view.store_view()).unwrap(); - let mut operation_metadata = - create_op_metadata(self.start_time.clone(), self.description.clone()); - operation_metadata.tags = self.tags.clone(); + self.op_metadata.end_time = Timestamp::now(); let parents = self.parent_ops.iter().map(|op| op.id().clone()).collect(); let store_operation = op_store::Operation { view_id, parents, - metadata: operation_metadata, + metadata: self.op_metadata, }; let new_op_id = base_repo .op_store() @@ -119,8 +113,9 @@ impl Transaction { } } -pub fn create_op_metadata(start_time: Timestamp, description: String) -> OperationMetadata { - let end_time = Timestamp::now(); +pub fn create_op_metadata(description: String) -> OperationMetadata { + let start_time = Timestamp::now(); + let end_time = start_time.clone(); let hostname = whoami::hostname(); let username = whoami::username(); OperationMetadata {