mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-08 21:55:47 +00:00
legacy_thrift_op_store: remove implementation write methods
This commit is contained in:
parent
c269b72fb3
commit
6b964218bf
1 changed files with 6 additions and 152 deletions
|
@ -15,16 +15,13 @@
|
|||
use std::collections::BTreeMap;
|
||||
use std::fmt::Debug;
|
||||
use std::fs::File;
|
||||
use std::io::{ErrorKind, Read, Write};
|
||||
use std::io::{ErrorKind, Read};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use itertools::Itertools;
|
||||
use tempfile::NamedTempFile;
|
||||
use thrift::protocol::{TCompactInputProtocol, TCompactOutputProtocol, TSerializable};
|
||||
use thrift::protocol::{TCompactInputProtocol, TSerializable};
|
||||
|
||||
use crate::backend::{CommitId, MillisSinceEpoch, Timestamp};
|
||||
use crate::content_hash::blake2b_hash;
|
||||
use crate::file_util::persist_content_addressed_temp_file;
|
||||
use crate::op_store::{
|
||||
BranchTarget, OpStore, OpStoreError, OpStoreResult, Operation, OperationId, OperationMetadata,
|
||||
RefTarget, View, ViewId, WorkspaceId,
|
||||
|
@ -72,13 +69,8 @@ impl OpStore for ThriftOpStore {
|
|||
Ok(View::from(&thrift_view))
|
||||
}
|
||||
|
||||
fn write_view(&self, view: &View) -> OpStoreResult<ViewId> {
|
||||
let id = ViewId::new(blake2b_hash(view).to_vec());
|
||||
let temp_file = NamedTempFile::new_in(&self.path)?;
|
||||
let thrift_view = simple_op_store_model::View::from(view);
|
||||
write_thrift(&thrift_view, &mut temp_file.as_file())?;
|
||||
persist_content_addressed_temp_file(temp_file, self.view_path(&id))?;
|
||||
Ok(id)
|
||||
fn write_view(&self, _view: &View) -> OpStoreResult<ViewId> {
|
||||
panic!("ThriftOpStore is readonly");
|
||||
}
|
||||
|
||||
fn read_operation(&self, id: &OperationId) -> OpStoreResult<Operation> {
|
||||
|
@ -88,13 +80,8 @@ impl OpStore for ThriftOpStore {
|
|||
Ok(Operation::from(&thrift_operation))
|
||||
}
|
||||
|
||||
fn write_operation(&self, operation: &Operation) -> OpStoreResult<OperationId> {
|
||||
let id = OperationId::new(blake2b_hash(operation).to_vec());
|
||||
let temp_file = NamedTempFile::new_in(&self.path)?;
|
||||
let thrift_operation = simple_op_store_model::Operation::from(operation);
|
||||
write_thrift(&thrift_operation, &mut temp_file.as_file())?;
|
||||
persist_content_addressed_temp_file(temp_file, self.operation_path(&id))?;
|
||||
Ok(id)
|
||||
fn write_operation(&self, _operation: &Operation) -> OpStoreResult<OperationId> {
|
||||
panic!("ThriftOpStore is readonly");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -103,21 +90,6 @@ pub fn read_thrift<T: TSerializable>(input: &mut impl Read) -> OpStoreResult<T>
|
|||
Ok(TSerializable::read_from_in_protocol(&mut protocol).unwrap())
|
||||
}
|
||||
|
||||
pub fn write_thrift<T: TSerializable>(
|
||||
thrift_object: &T,
|
||||
output: &mut impl Write,
|
||||
) -> OpStoreResult<()> {
|
||||
let mut protocol = TCompactOutputProtocol::new(output);
|
||||
thrift_object.write_to_out_protocol(&mut protocol)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
impl From<&Timestamp> for simple_op_store_model::Timestamp {
|
||||
fn from(timestamp: &Timestamp) -> Self {
|
||||
simple_op_store_model::Timestamp::new(timestamp.timestamp.0, timestamp.tz_offset)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&simple_op_store_model::Timestamp> for Timestamp {
|
||||
fn from(timestamp: &simple_op_store_model::Timestamp) -> Self {
|
||||
Timestamp {
|
||||
|
@ -127,29 +99,6 @@ impl From<&simple_op_store_model::Timestamp> for Timestamp {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<&OperationMetadata> for simple_op_store_model::OperationMetadata {
|
||||
fn from(metadata: &OperationMetadata) -> Self {
|
||||
let start_time = simple_op_store_model::Timestamp::from(&metadata.start_time);
|
||||
let end_time = simple_op_store_model::Timestamp::from(&metadata.end_time);
|
||||
let description = metadata.description.clone();
|
||||
let hostname = metadata.hostname.clone();
|
||||
let username = metadata.username.clone();
|
||||
let tags: BTreeMap<String, String> = metadata
|
||||
.tags
|
||||
.iter()
|
||||
.map(|(x, y)| (x.clone(), y.clone()))
|
||||
.collect();
|
||||
simple_op_store_model::OperationMetadata::new(
|
||||
start_time,
|
||||
end_time,
|
||||
description,
|
||||
hostname,
|
||||
username,
|
||||
tags,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&simple_op_store_model::OperationMetadata> for OperationMetadata {
|
||||
fn from(metadata: &simple_op_store_model::OperationMetadata) -> Self {
|
||||
let start_time = Timestamp::from(&metadata.start_time);
|
||||
|
@ -173,87 +122,6 @@ impl From<&simple_op_store_model::OperationMetadata> for OperationMetadata {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<&Operation> for simple_op_store_model::Operation {
|
||||
fn from(operation: &Operation) -> Self {
|
||||
let view_id = operation.view_id.as_bytes().to_vec();
|
||||
let mut parents = vec![];
|
||||
for parent in &operation.parents {
|
||||
parents.push(parent.to_bytes());
|
||||
}
|
||||
let metadata = Box::new(simple_op_store_model::OperationMetadata::from(
|
||||
&operation.metadata,
|
||||
));
|
||||
simple_op_store_model::Operation::new(view_id, parents, metadata)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&View> for simple_op_store_model::View {
|
||||
fn from(view: &View) -> Self {
|
||||
let mut wc_commit_ids = BTreeMap::new();
|
||||
for (workspace_id, commit_id) in &view.wc_commit_ids {
|
||||
wc_commit_ids.insert(workspace_id.as_str().to_string(), commit_id.to_bytes());
|
||||
}
|
||||
|
||||
let mut head_ids = vec![];
|
||||
for head_id in &view.head_ids {
|
||||
head_ids.push(head_id.to_bytes());
|
||||
}
|
||||
|
||||
let mut public_head_ids = vec![];
|
||||
for head_id in &view.public_head_ids {
|
||||
public_head_ids.push(head_id.to_bytes());
|
||||
}
|
||||
|
||||
let mut branches = vec![];
|
||||
for (name, target) in &view.branches {
|
||||
let local_target = target
|
||||
.local_target
|
||||
.as_ref()
|
||||
.map(simple_op_store_model::RefTarget::from);
|
||||
let mut remote_branches = vec![];
|
||||
for (remote_name, target) in &target.remote_targets {
|
||||
remote_branches.push(simple_op_store_model::RemoteBranch::new(
|
||||
remote_name.clone(),
|
||||
simple_op_store_model::RefTarget::from(target),
|
||||
));
|
||||
}
|
||||
branches.push(simple_op_store_model::Branch::new(
|
||||
name.clone(),
|
||||
local_target,
|
||||
remote_branches,
|
||||
));
|
||||
}
|
||||
|
||||
let mut tags = vec![];
|
||||
for (name, target) in &view.tags {
|
||||
tags.push(simple_op_store_model::Tag::new(
|
||||
name.clone(),
|
||||
simple_op_store_model::RefTarget::from(target),
|
||||
));
|
||||
}
|
||||
|
||||
let mut git_refs = vec![];
|
||||
for (git_ref_name, target) in &view.git_refs {
|
||||
git_refs.push(simple_op_store_model::GitRef::new(
|
||||
git_ref_name.clone(),
|
||||
simple_op_store_model::RefTarget::from(target),
|
||||
));
|
||||
}
|
||||
|
||||
let git_head = view.git_head.as_ref().map(|git_head| git_head.to_bytes());
|
||||
|
||||
simple_op_store_model::View::new(
|
||||
head_ids,
|
||||
public_head_ids,
|
||||
wc_commit_ids,
|
||||
branches,
|
||||
tags,
|
||||
git_refs,
|
||||
git_head,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&simple_op_store_model::Operation> for Operation {
|
||||
fn from(operation: &simple_op_store_model::Operation) -> Self {
|
||||
let operation_id_from_thrift = |parent: &Vec<u8>| OperationId::new(parent.clone());
|
||||
|
@ -328,20 +196,6 @@ impl From<&simple_op_store_model::View> for View {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<&RefTarget> for simple_op_store_model::RefTarget {
|
||||
fn from(ref_target: &RefTarget) -> Self {
|
||||
match ref_target {
|
||||
RefTarget::Normal(id) => simple_op_store_model::RefTarget::CommitId(id.to_bytes()),
|
||||
RefTarget::Conflict { removes, adds } => {
|
||||
let adds = adds.iter().map(|id| id.to_bytes()).collect_vec();
|
||||
let removes = removes.iter().map(|id| id.to_bytes()).collect_vec();
|
||||
let ref_conflict_thrift = simple_op_store_model::RefConflict::new(removes, adds);
|
||||
simple_op_store_model::RefTarget::Conflict(ref_conflict_thrift)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&simple_op_store_model::RefTarget> for RefTarget {
|
||||
fn from(thrift_ref_target: &simple_op_store_model::RefTarget) -> Self {
|
||||
match thrift_ref_target {
|
||||
|
|
Loading…
Reference in a new issue