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

transaction: store full OperationMetadata instead of parts

We already store the description, start time, and tags. It's easier to
store the whole struct.
This commit is contained in:
Martin von Zweigbergk 2022-11-13 08:59:59 -08:00 committed by Martin von Zweigbergk
parent 4aa4b838b4
commit 43cfb98f78
2 changed files with 11 additions and 16 deletions

View file

@ -24,7 +24,7 @@ use once_cell::sync::OnceCell;
use thiserror::Error; use thiserror::Error;
use self::dirty_cell::DirtyCell; 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::Commit;
use crate::commit_builder::CommitBuilder; use crate::commit_builder::CommitBuilder;
use crate::dag_walk::topo_order_reverse; use crate::dag_walk::topo_order_reverse;
@ -137,7 +137,7 @@ impl ReadonlyRepo {
let op_heads_path = repo_path.join("op_heads"); let op_heads_path = repo_path.join("op_heads");
fs::create_dir(&op_heads_path).context(&op_heads_path)?; fs::create_dir(&op_heads_path).context(&op_heads_path)?;
let operation_metadata = 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) = let (op_heads_store, init_op) =
OpHeadsStore::init(op_heads_path, &op_store, &root_view, operation_metadata); OpHeadsStore::init(op_heads_path, &op_store, &root_view, operation_metadata);
let op_heads_store = Arc::new(op_heads_store); let op_heads_store = Arc::new(op_heads_store);

View file

@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use std::collections::HashMap;
use std::sync::Arc; use std::sync::Arc;
use crate::backend::Timestamp; use crate::backend::Timestamp;
@ -27,20 +26,17 @@ use crate::view::View;
pub struct Transaction { pub struct Transaction {
repo: Option<MutableRepo>, repo: Option<MutableRepo>,
parent_ops: Vec<Operation>, parent_ops: Vec<Operation>,
description: String, op_metadata: OperationMetadata,
start_time: Timestamp,
tags: HashMap<String, String>,
} }
impl Transaction { impl Transaction {
pub fn new(mut_repo: MutableRepo, description: &str) -> Transaction { pub fn new(mut_repo: MutableRepo, description: &str) -> Transaction {
let parent_ops = vec![mut_repo.base_repo().operation().clone()]; let parent_ops = vec![mut_repo.base_repo().operation().clone()];
let op_metadata = create_op_metadata(description.to_string());
Transaction { Transaction {
repo: Some(mut_repo), repo: Some(mut_repo),
parent_ops, parent_ops,
description: description.to_owned(), op_metadata,
start_time: Timestamp::now(),
tags: Default::default(),
} }
} }
@ -49,7 +45,7 @@ impl Transaction {
} }
pub fn set_tag(&mut self, key: String, value: String) { 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 { pub fn repo(&self) -> &MutableRepo {
@ -96,14 +92,12 @@ impl Transaction {
let index = base_repo.index_store().write_index(mut_index).unwrap(); 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 view_id = base_repo.op_store().write_view(view.store_view()).unwrap();
let mut operation_metadata = self.op_metadata.end_time = Timestamp::now();
create_op_metadata(self.start_time.clone(), self.description.clone());
operation_metadata.tags = self.tags.clone();
let parents = self.parent_ops.iter().map(|op| op.id().clone()).collect(); let parents = self.parent_ops.iter().map(|op| op.id().clone()).collect();
let store_operation = op_store::Operation { let store_operation = op_store::Operation {
view_id, view_id,
parents, parents,
metadata: operation_metadata, metadata: self.op_metadata,
}; };
let new_op_id = base_repo let new_op_id = base_repo
.op_store() .op_store()
@ -119,8 +113,9 @@ impl Transaction {
} }
} }
pub fn create_op_metadata(start_time: Timestamp, description: String) -> OperationMetadata { pub fn create_op_metadata(description: String) -> OperationMetadata {
let end_time = Timestamp::now(); let start_time = Timestamp::now();
let end_time = start_time.clone();
let hostname = whoami::hostname(); let hostname = whoami::hostname();
let username = whoami::username(); let username = whoami::username();
OperationMetadata { OperationMetadata {