mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-28 23:55:54 +00:00
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:
parent
4aa4b838b4
commit
43cfb98f78
2 changed files with 11 additions and 16 deletions
|
@ -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);
|
||||
|
|
|
@ -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<MutableRepo>,
|
||||
parent_ops: Vec<Operation>,
|
||||
description: String,
|
||||
start_time: Timestamp,
|
||||
tags: HashMap<String, String>,
|
||||
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 {
|
||||
|
|
Loading…
Reference in a new issue