diff --git a/cli/tests/test_git_import_export.rs b/cli/tests/test_git_import_export.rs index d28bb2c03..fc537d14f 100644 --- a/cli/tests/test_git_import_export.rs +++ b/cli/tests/test_git_import_export.rs @@ -15,7 +15,6 @@ use std::path::Path; use itertools::Itertools as _; use jj_lib::backend::CommitId; -use jj_lib::object_id::ObjectId as _; use crate::common::TestEnvironment; diff --git a/lib/src/default_revset_engine.rs b/lib/src/default_revset_engine.rs index fd4265b1b..8c69881e8 100644 --- a/lib/src/default_revset_engine.rs +++ b/lib/src/default_revset_engine.rs @@ -1001,7 +1001,6 @@ mod tests { use super::*; use crate::backend::{ChangeId, CommitId}; use crate::default_index::DefaultMutableIndex; - use crate::object_id::ObjectId; /// Generator of unique 16-byte ChangeId excluding root id fn change_id_generator() -> impl FnMut() -> ChangeId { diff --git a/lib/src/id_prefix.rs b/lib/src/id_prefix.rs index 1d599602a..e0fe7daa1 100644 --- a/lib/src/id_prefix.rs +++ b/lib/src/id_prefix.rs @@ -446,7 +446,6 @@ fn unwrap_as_short_key(key_bytes: &[u8]) -> &[u8; N] { mod tests { use super::*; use crate::backend::ChangeId; - use crate::object_id::ObjectId; #[derive(Clone, Copy, Eq, PartialEq)] struct Position(usize); diff --git a/lib/src/object_id.rs b/lib/src/object_id.rs index 9c43f2dc3..734599ef2 100644 --- a/lib/src/object_id.rs +++ b/lib/src/object_id.rs @@ -15,12 +15,9 @@ #![allow(missing_docs)] pub trait ObjectId { - fn new(value: Vec) -> Self; fn object_type(&self) -> String; - fn from_bytes(bytes: &[u8]) -> Self; fn as_bytes(&self) -> &[u8]; fn to_bytes(&self) -> Vec; - fn from_hex(hex: &str) -> Self; fn hex(&self) -> String; } @@ -36,6 +33,20 @@ macro_rules! id_type { macro_rules! impl_id_type { ($name:ident) => { + impl $name { + pub fn new(value: Vec) -> Self { + Self(value) + } + + pub fn from_bytes(bytes: &[u8]) -> Self { + Self(bytes.to_vec()) + } + + pub fn from_hex(hex: &str) -> Self { + Self(hex::decode(hex).unwrap()) + } + } + 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() @@ -43,10 +54,6 @@ macro_rules! impl_id_type { } impl crate::object_id::ObjectId for $name { - fn new(value: Vec) -> Self { - Self(value) - } - fn object_type(&self) -> String { stringify!($name) .strip_suffix("Id") @@ -55,10 +62,6 @@ macro_rules! impl_id_type { .to_string() } - fn from_bytes(bytes: &[u8]) -> Self { - Self(bytes.to_vec()) - } - fn as_bytes(&self) -> &[u8] { &self.0 } @@ -67,10 +70,6 @@ macro_rules! impl_id_type { self.0.clone() } - fn from_hex(hex: &str) -> Self { - Self(hex::decode(hex).unwrap()) - } - fn hex(&self) -> String { hex::encode(&self.0) } diff --git a/lib/src/op_walk.rs b/lib/src/op_walk.rs index 6fab77cd0..adae474f0 100644 --- a/lib/src/op_walk.rs +++ b/lib/src/op_walk.rs @@ -22,7 +22,7 @@ use std::sync::Arc; use itertools::Itertools as _; use thiserror::Error; -use crate::object_id::{HexPrefix, ObjectId as _}; +use crate::object_id::HexPrefix; use crate::op_heads_store::{OpHeadResolutionError, OpHeadsStore}; use crate::op_store::{OpStore, OpStoreError, OpStoreResult, OperationId}; use crate::operation::Operation; diff --git a/lib/src/refs.rs b/lib/src/refs.rs index 56514312f..14751efa2 100644 --- a/lib/src/refs.rs +++ b/lib/src/refs.rs @@ -205,7 +205,6 @@ pub fn classify_branch_push_action(targets: TrackingRefPair) -> BranchPushAction #[cfg(test)] mod tests { use super::*; - use crate::object_id::ObjectId; use crate::op_store::RemoteRefState; fn new_remote_ref(target: RefTarget) -> RemoteRef { diff --git a/lib/src/settings.rs b/lib/src/settings.rs index 22b41c271..be51e237c 100644 --- a/lib/src/settings.rs +++ b/lib/src/settings.rs @@ -24,7 +24,6 @@ use rand_chacha::ChaCha20Rng; use crate::backend::{ChangeId, Commit, Signature, Timestamp}; use crate::fmt_util::binary_prefix; use crate::fsmonitor::FsmonitorKind; -use crate::object_id::ObjectId; use crate::signing::SignBehavior; #[derive(Debug, Clone)] diff --git a/lib/tests/test_commit_builder.rs b/lib/tests/test_commit_builder.rs index eb6bc38f7..976069a36 100644 --- a/lib/tests/test_commit_builder.rs +++ b/lib/tests/test_commit_builder.rs @@ -15,7 +15,6 @@ use jj_lib::backend::{ChangeId, MillisSinceEpoch, Signature, Timestamp}; use jj_lib::matchers::EverythingMatcher; use jj_lib::merged_tree::DiffSummary; -use jj_lib::object_id::ObjectId; use jj_lib::repo::Repo; use jj_lib::repo_path::{RepoPath, RepoPathBuf}; use jj_lib::settings::UserSettings; diff --git a/lib/tests/test_local_working_copy.rs b/lib/tests/test_local_working_copy.rs index 8445ea458..85134612b 100644 --- a/lib/tests/test_local_working_copy.rs +++ b/lib/tests/test_local_working_copy.rs @@ -31,7 +31,6 @@ use jj_lib::fsmonitor::FsmonitorKind; use jj_lib::local_working_copy::LocalWorkingCopy; use jj_lib::merge::Merge; use jj_lib::merged_tree::MergedTreeBuilder; -use jj_lib::object_id::ObjectId; use jj_lib::op_store::{OperationId, WorkspaceId}; use jj_lib::repo::{ReadonlyRepo, Repo}; use jj_lib::repo_path::{RepoPath, RepoPathBuf, RepoPathComponent};