Skip to content

Commit

Permalink
transaction: keep whole operation objects, not just IDs, of parents (#…
Browse files Browse the repository at this point in the history
…111)

We already have the operation objects, and keeping them will allow
some cleanup (see next change).
  • Loading branch information
martinvonz committed Mar 27, 2022
1 parent dc98c75 commit c58474b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
3 changes: 1 addition & 2 deletions lib/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
15 changes: 8 additions & 7 deletions lib/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ 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<MutableRepo>,
parents: Vec<OperationId>,
parent_ops: Vec<Operation>,
description: String,
start_time: Timestamp,
tags: HashMap<String, String>,
}

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(),
Expand All @@ -47,8 +47,8 @@ impl Transaction {
self.repo.as_ref().unwrap().base_repo()
}

pub fn set_parents(&mut self, parents: Vec<OperationId>) {
self.parents = parents;
pub fn set_parent_ops(&mut self, parent_ops: Vec<Operation>) {
self.parent_ops = parent_ops;
}

pub fn set_tag(&mut self, key: String, value: String) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c58474b

Please sign in to comment.