From 4d64687bc36cbe6b934584fd37f1d7532235d5b2 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sat, 26 Mar 2022 10:10:28 -0700 Subject: [PATCH] transaction: keep whole operation objects, not just IDs, of parents (#111) We already have the operation objects, and keeping them will allow some cleanup (see next change). --- lib/src/repo.rs | 3 +-- lib/src/transaction.rs | 15 ++++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/src/repo.rs b/lib/src/repo.rs index b0301e6c0..bb8d8c416 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -407,8 +407,7 @@ impl RepoLoader { merged_repo.merge(&base_repo, &other_repo); merged_repo.rebase_descendants(user_settings); } - let op_parent_ids = op_heads.iter().map(|op| op.id().clone()).collect(); - tx.set_parents(op_parent_ids); + tx.set_parent_ops(op_heads); tx.write() } diff --git a/lib/src/transaction.rs b/lib/src/transaction.rs index 4e9cd48b7..1f1e92a1f 100644 --- a/lib/src/transaction.rs +++ b/lib/src/transaction.rs @@ -18,14 +18,14 @@ use std::sync::Arc; use crate::backend::Timestamp; use crate::index::ReadonlyIndex; use crate::op_store; -use crate::op_store::{OperationId, OperationMetadata}; +use crate::op_store::OperationMetadata; use crate::operation::Operation; use crate::repo::{MutableRepo, ReadonlyRepo, RepoLoader}; use crate::view::View; pub struct Transaction { repo: Option, - parents: Vec, + parent_ops: Vec, description: String, start_time: Timestamp, tags: HashMap, @@ -33,10 +33,10 @@ pub struct Transaction { impl Transaction { pub fn new(mut_repo: MutableRepo, description: &str) -> Transaction { - let parents = vec![mut_repo.base_repo().op_id().clone()]; + let parent_ops = vec![mut_repo.base_repo().operation().clone()]; Transaction { repo: Some(mut_repo), - parents, + parent_ops, description: description.to_owned(), start_time: Timestamp::now(), tags: Default::default(), @@ -47,8 +47,8 @@ impl Transaction { self.repo.as_ref().unwrap().base_repo() } - pub fn set_parents(&mut self, parents: Vec) { - self.parents = parents; + pub fn set_parent_ops(&mut self, parent_ops: Vec) { + self.parent_ops = parent_ops; } pub fn set_tag(&mut self, key: String, value: String) { @@ -82,9 +82,10 @@ impl Transaction { let mut operation_metadata = OperationMetadata::new(self.description.clone(), self.start_time.clone()); operation_metadata.tags = self.tags.clone(); + let parents = self.parent_ops.iter().map(|op| op.id().clone()).collect(); let store_operation = op_store::Operation { view_id, - parents: self.parents.clone(), + parents, metadata: operation_metadata, }; let new_op_id = base_repo