mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-26 22:10:52 +00:00
op_store: make ViewId
and OperationId
implement ObjectId
This commit is contained in:
parent
769426f99a
commit
84a60d15bc
8 changed files with 16 additions and 73 deletions
|
@ -16,7 +16,7 @@
|
|||
|
||||
use std::any::Any;
|
||||
use std::collections::BTreeMap;
|
||||
use std::fmt::{Debug, Error, Formatter};
|
||||
use std::fmt::Debug;
|
||||
use std::io::Read;
|
||||
use std::result::Result;
|
||||
use std::vec::Vec;
|
||||
|
@ -43,14 +43,14 @@ macro_rules! id_type {
|
|||
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
|
||||
$vis struct $name(Vec<u8>);
|
||||
}
|
||||
impl_id_type!($name);
|
||||
$crate::backend::impl_id_type!($name);
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! impl_id_type {
|
||||
($name:ident) => {
|
||||
impl Debug for $name {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
|
||||
impl std::fmt::Debug for $name {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||
f.debug_tuple(stringify!($name)).field(&self.hex()).finish()
|
||||
}
|
||||
}
|
||||
|
@ -91,6 +91,8 @@ macro_rules! impl_id_type {
|
|||
};
|
||||
}
|
||||
|
||||
pub(crate) use {id_type, impl_id_type};
|
||||
|
||||
id_type!(pub CommitId);
|
||||
id_type!(pub ChangeId);
|
||||
id_type!(pub TreeId);
|
||||
|
|
|
@ -22,7 +22,7 @@ use itertools::Itertools as _;
|
|||
use once_cell::sync::Lazy;
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::backend::{CommitId, Timestamp};
|
||||
use crate::backend::{id_type, CommitId, ObjectId, Timestamp};
|
||||
use crate::conflicts::Conflict;
|
||||
use crate::content_hash::ContentHash;
|
||||
|
||||
|
@ -53,71 +53,8 @@ impl WorkspaceId {
|
|||
}
|
||||
}
|
||||
|
||||
content_hash! {
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
|
||||
pub struct ViewId(Vec<u8>);
|
||||
}
|
||||
|
||||
impl Debug for ViewId {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
|
||||
f.debug_tuple("ViewId").field(&self.hex()).finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewId {
|
||||
pub fn new(value: Vec<u8>) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
|
||||
pub fn from_hex(hex: &str) -> Self {
|
||||
Self(hex::decode(hex).unwrap())
|
||||
}
|
||||
|
||||
pub fn as_bytes(&self) -> &[u8] {
|
||||
&self.0
|
||||
}
|
||||
|
||||
pub fn to_bytes(&self) -> Vec<u8> {
|
||||
self.0.clone()
|
||||
}
|
||||
|
||||
pub fn hex(&self) -> String {
|
||||
hex::encode(&self.0)
|
||||
}
|
||||
}
|
||||
|
||||
content_hash! {
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
|
||||
pub struct OperationId(Vec<u8>);
|
||||
}
|
||||
|
||||
impl Debug for OperationId {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
|
||||
f.debug_tuple("OperationId").field(&self.hex()).finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl OperationId {
|
||||
pub fn new(value: Vec<u8>) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
|
||||
pub fn from_hex(hex: &str) -> Self {
|
||||
Self(hex::decode(hex).unwrap())
|
||||
}
|
||||
|
||||
pub fn as_bytes(&self) -> &[u8] {
|
||||
&self.0
|
||||
}
|
||||
|
||||
pub fn to_bytes(&self) -> Vec<u8> {
|
||||
self.0.clone()
|
||||
}
|
||||
|
||||
pub fn hex(&self) -> String {
|
||||
hex::encode(&self.0)
|
||||
}
|
||||
}
|
||||
id_type!(pub ViewId);
|
||||
id_type!(pub OperationId);
|
||||
|
||||
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
|
||||
pub struct RefTarget {
|
||||
|
|
|
@ -18,6 +18,7 @@ use std::fmt::{Debug, Formatter};
|
|||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use crate::backend::ObjectId;
|
||||
use crate::lock::FileLock;
|
||||
use crate::op_heads_store::{OpHeadsStore, OpHeadsStoreLock};
|
||||
use crate::op_store::OperationId;
|
||||
|
@ -127,6 +128,7 @@ mod tests {
|
|||
|
||||
use itertools::Itertools;
|
||||
|
||||
use crate::backend::ObjectId;
|
||||
use crate::op_heads_store::OpHeadsStore;
|
||||
use crate::op_store::OperationId;
|
||||
use crate::simple_op_heads_store::SimpleOpHeadsStore;
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
use std::path::Path;
|
||||
|
||||
use jj_lib::backend::CommitId;
|
||||
use jj_lib::backend::{CommitId, ObjectId};
|
||||
use jj_lib::repo::Repo;
|
||||
use test_case::test_case;
|
||||
use testutils::{create_random_commit, write_random_commit, TestRepo};
|
||||
|
|
|
@ -21,7 +21,7 @@ use std::os::unix::net::UnixListener;
|
|||
use std::sync::Arc;
|
||||
|
||||
use itertools::Itertools;
|
||||
use jj_lib::backend::{TreeId, TreeValue};
|
||||
use jj_lib::backend::{ObjectId, TreeId, TreeValue};
|
||||
use jj_lib::conflicts::Conflict;
|
||||
use jj_lib::fsmonitor::FsmonitorKind;
|
||||
#[cfg(unix)]
|
||||
|
|
|
@ -16,7 +16,7 @@ use std::cmp::max;
|
|||
use std::thread;
|
||||
|
||||
use assert_matches::assert_matches;
|
||||
use jj_lib::backend::TreeId;
|
||||
use jj_lib::backend::{ObjectId, TreeId};
|
||||
use jj_lib::op_store::OperationId;
|
||||
use jj_lib::repo::{Repo, StoreFactories};
|
||||
use jj_lib::repo_path::RepoPath;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
use clap::Subcommand;
|
||||
use jj_lib::backend::ObjectId;
|
||||
use jj_lib::op_store::{BranchTarget, RefTarget};
|
||||
use jj_lib::operation;
|
||||
use jj_lib::repo::Repo;
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
use std::io;
|
||||
|
||||
use itertools::Itertools as _;
|
||||
use jj_lib::backend::ObjectId;
|
||||
use jj_lib::op_store::{OperationId, OperationMetadata};
|
||||
use jj_lib::operation::Operation;
|
||||
use jj_lib::repo::ReadonlyRepo;
|
||||
|
|
Loading…
Reference in a new issue