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

op_store: move logic out of OperationMetadata

`OperationMetadata` is a data type used in the interface. It seems
wrong for it to know where to get data from.
This commit is contained in:
Martin von Zweigbergk 2022-11-12 17:53:52 -08:00 committed by Martin von Zweigbergk
parent 9f0ae4586b
commit 4aa4b838b4
3 changed files with 17 additions and 21 deletions

View file

@ -244,22 +244,6 @@ content_hash! {
}
}
impl OperationMetadata {
pub fn new(description: String, start_time: Timestamp) -> Self {
let end_time = Timestamp::now();
let hostname = whoami::hostname();
let username = whoami::username();
OperationMetadata {
start_time,
end_time,
description,
hostname,
username,
tags: Default::default(),
}
}
}
#[derive(Debug, Error)]
pub enum OpStoreError {
#[error("Operation not found")]

View file

@ -33,9 +33,7 @@ use crate::index::{IndexRef, MutableIndex, ReadonlyIndex};
use crate::index_store::IndexStore;
use crate::local_backend::LocalBackend;
use crate::op_heads_store::{LockedOpHeads, OpHeads, OpHeadsStore};
use crate::op_store::{
BranchTarget, OpStore, OperationId, OperationMetadata, RefTarget, WorkspaceId,
};
use crate::op_store::{BranchTarget, OpStore, OperationId, RefTarget, WorkspaceId};
use crate::operation::Operation;
use crate::rewrite::DescendantRebaser;
use crate::settings::{RepoSettings, UserSettings};
@ -139,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 =
OperationMetadata::new("initialize repo".to_string(), Timestamp::now());
crate::transaction::create_op_metadata(Timestamp::now(), "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);

View file

@ -97,7 +97,7 @@ impl Transaction {
let view_id = base_repo.op_store().write_view(view.store_view()).unwrap();
let mut operation_metadata =
OperationMetadata::new(self.description.clone(), self.start_time.clone());
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 store_operation = op_store::Operation {
@ -119,6 +119,20 @@ impl Transaction {
}
}
pub fn create_op_metadata(start_time: Timestamp, description: String) -> OperationMetadata {
let end_time = Timestamp::now();
let hostname = whoami::hostname();
let username = whoami::username();
OperationMetadata {
start_time,
end_time,
description,
hostname,
username,
tags: Default::default(),
}
}
struct NewRepoData {
operation: Operation,
view: View,