object_id: extract ObjectId trait and macros to separate module

I'm going to add a prefix resolution method to OpStore, but OpStore is
unrelated to the index. I think ObjectId, HexPrefix, and PrefixResolution can
be extracted to this module.
This commit is contained in:
Yuya Nishihara 2024-01-04 16:18:04 +09:00
parent dbaee198e6
commit fa5e40719c
62 changed files with 187 additions and 132 deletions

View file

@ -30,7 +30,7 @@ use clap::builder::{NonEmptyStringValueParser, TypedValueParser, ValueParserFact
use clap::{Arg, ArgAction, ArgMatches, Command, FromArgMatches};
use indexmap::{IndexMap, IndexSet};
use itertools::Itertools;
use jj_lib::backend::{BackendError, ChangeId, CommitId, MergedTreeId, ObjectId};
use jj_lib::backend::{BackendError, ChangeId, CommitId, MergedTreeId};
use jj_lib::commit::Commit;
use jj_lib::git::{
FailedRefExport, FailedRefExportReason, GitConfigParseError, GitExportError, GitImportError,
@ -42,6 +42,7 @@ use jj_lib::hex_util::to_reverse_hex;
use jj_lib::id_prefix::IdPrefixContext;
use jj_lib::matchers::{EverythingMatcher, Matcher, PrefixMatcher};
use jj_lib::merged_tree::MergedTree;
use jj_lib::object_id::ObjectId;
use jj_lib::op_heads_store::{self, OpHeadResolutionError};
use jj_lib::op_store::{OpStoreError, OperationId, WorkspaceId};
use jj_lib::op_walk::OpsetEvaluationError;

View file

@ -14,7 +14,7 @@
use std::io::Write;
use jj_lib::backend::ObjectId;
use jj_lib::object_id::ObjectId;
use tracing::instrument;
use crate::cli_util::{

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use jj_lib::backend::ObjectId;
use jj_lib::object_id::ObjectId;
use jj_lib::rewrite::back_out_commit;
use tracing::instrument;

View file

@ -19,8 +19,9 @@ use std::str::FromStr;
use clap::builder::NonEmptyStringValueParser;
use itertools::Itertools;
use jj_lib::backend::{CommitId, ObjectId};
use jj_lib::backend::CommitId;
use jj_lib::git;
use jj_lib::object_id::ObjectId;
use jj_lib::op_store::{RefTarget, RemoteRef};
use jj_lib::repo::Repo;
use jj_lib::revset::{self, RevsetExpression};

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use jj_lib::backend::ObjectId;
use jj_lib::object_id::ObjectId;
use tracing::instrument;
use crate::cli_util::{join_message_paragraphs, CommandError, CommandHelper, RevisionArg};

View file

@ -13,8 +13,9 @@
// limitations under the License.
use itertools::Itertools;
use jj_lib::backend::{ObjectId, TreeValue};
use jj_lib::backend::TreeValue;
use jj_lib::merged_tree::MergedTreeBuilder;
use jj_lib::object_id::ObjectId;
use tracing::instrument;
use crate::cli_util::{user_error, CommandError, CommandHelper, RevisionArg};

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use jj_lib::backend::ObjectId;
use jj_lib::object_id::ObjectId;
use jj_lib::repo::Repo;
use jj_lib::rewrite::merge_commit_trees;
use tracing::instrument;

View file

@ -17,9 +17,9 @@ use std::fmt::Debug;
use std::io::Write as _;
use clap::Subcommand;
use jj_lib::backend::ObjectId;
use jj_lib::default_index::{AsCompositeIndex as _, DefaultIndexStore, DefaultReadonlyIndex};
use jj_lib::local_working_copy::LocalWorkingCopy;
use jj_lib::object_id::ObjectId;
use jj_lib::repo::Repo;
use jj_lib::working_copy::WorkingCopy;
use jj_lib::{op_walk, revset};

View file

@ -14,7 +14,7 @@
use std::io::{self, Read, Write};
use jj_lib::backend::ObjectId;
use jj_lib::object_id::ObjectId;
use tracing::instrument;
use crate::cli_util::{join_message_paragraphs, CommandError, CommandHelper, RevisionArg};

View file

@ -14,8 +14,8 @@
use std::io::Write;
use jj_lib::backend::ObjectId;
use jj_lib::matchers::EverythingMatcher;
use jj_lib::object_id::ObjectId;
use jj_lib::rewrite::merge_commit_trees;
use tracing::instrument;

View file

@ -14,7 +14,7 @@
use std::io::Write;
use jj_lib::backend::ObjectId;
use jj_lib::object_id::ObjectId;
use tracing::instrument;
use crate::cli_util::{CommandError, CommandHelper, RevisionArg};

View file

@ -23,11 +23,12 @@ use std::{fmt, fs, io};
use clap::{ArgGroup, Subcommand};
use itertools::Itertools;
use jj_lib::backend::{ObjectId, TreeValue};
use jj_lib::backend::TreeValue;
use jj_lib::git::{
self, parse_gitmodules, GitBranchPushTargets, GitFetchError, GitFetchStats, GitPushError,
};
use jj_lib::git_backend::GitBackend;
use jj_lib::object_id::ObjectId;
use jj_lib::op_store::RefTarget;
use jj_lib::refs::{
classify_branch_push_action, BranchPushAction, BranchPushUpdate, TrackingRefPair,

View file

@ -13,7 +13,7 @@
// limitations under the License.
use clap::ArgGroup;
use jj_lib::backend::ObjectId;
use jj_lib::object_id::ObjectId;
use jj_lib::repo::Repo;
use jj_lib::rewrite::merge_commit_trees;
use tracing::instrument;

View file

@ -17,7 +17,7 @@ use std::slice;
use clap::Subcommand;
use itertools::Itertools as _;
use jj_lib::backend::ObjectId;
use jj_lib::object_id::ObjectId;
use jj_lib::op_store::OperationId;
use jj_lib::op_walk;
use jj_lib::repo::Repo;

View file

@ -19,8 +19,9 @@ use std::sync::Arc;
use clap::ArgGroup;
use indexmap::IndexSet;
use itertools::Itertools;
use jj_lib::backend::{CommitId, ObjectId};
use jj_lib::backend::CommitId;
use jj_lib::commit::Commit;
use jj_lib::object_id::ObjectId;
use jj_lib::repo::{ReadonlyRepo, Repo};
use jj_lib::revset::{RevsetExpression, RevsetIteratorExt};
use jj_lib::rewrite::{rebase_commit, rebase_commit_with_options, EmptyBehaviour, RebaseOptions};

View file

@ -16,8 +16,9 @@ use std::collections::BTreeMap;
use std::io::Write;
use itertools::Itertools;
use jj_lib::backend::{ObjectId, TreeValue};
use jj_lib::backend::TreeValue;
use jj_lib::merge::MergedTreeValue;
use jj_lib::object_id::ObjectId;
use jj_lib::repo_path::RepoPathBuf;
use tracing::instrument;

View file

@ -14,7 +14,7 @@
use std::io::Write;
use jj_lib::backend::ObjectId;
use jj_lib::object_id::ObjectId;
use jj_lib::rewrite::{merge_commit_trees, restore_tree};
use tracing::instrument;

View file

@ -13,7 +13,7 @@
// limitations under the License.
use std::io::Write;
use jj_lib::backend::ObjectId;
use jj_lib::object_id::ObjectId;
use jj_lib::repo::Repo;
use jj_lib::rewrite::merge_commit_trees;
use tracing::instrument;

View file

@ -13,7 +13,7 @@
// limitations under the License.
use clap::parser::ValueSource;
use jj_lib::backend::ObjectId;
use jj_lib::object_id::ObjectId;
use jj_lib::revset;
use tracing::instrument;

View file

@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use jj_lib::backend::ObjectId;
use jj_lib::matchers::EverythingMatcher;
use jj_lib::object_id::ObjectId;
use jj_lib::rewrite::merge_commit_trees;
use tracing::instrument;

View file

@ -18,8 +18,8 @@ use std::io::Write;
use clap::Subcommand;
use itertools::Itertools;
use jj_lib::backend::ObjectId;
use jj_lib::file_util;
use jj_lib::object_id::ObjectId;
use jj_lib::op_store::WorkspaceId;
use jj_lib::repo::Repo;
use jj_lib::rewrite::merge_commit_trees;

View file

@ -18,10 +18,11 @@ use std::io;
use std::rc::Rc;
use itertools::Itertools as _;
use jj_lib::backend::{ChangeId, CommitId, ObjectId as _};
use jj_lib::backend::{ChangeId, CommitId};
use jj_lib::commit::Commit;
use jj_lib::hex_util::to_reverse_hex;
use jj_lib::id_prefix::IdPrefixContext;
use jj_lib::object_id::ObjectId as _;
use jj_lib::op_store::{RefTarget, WorkspaceId};
use jj_lib::repo::Repo;
use jj_lib::{git, rewrite};

View file

@ -19,7 +19,7 @@ use std::ops::Range;
use futures::{try_join, Stream, StreamExt};
use itertools::Itertools;
use jj_lib::backend::{BackendResult, ObjectId, TreeValue};
use jj_lib::backend::{BackendResult, TreeValue};
use jj_lib::commit::Commit;
use jj_lib::conflicts::{materialize_tree_value, MaterializedTreeValue};
use jj_lib::diff::{Diff, DiffHunk};
@ -27,6 +27,7 @@ use jj_lib::files::DiffLine;
use jj_lib::matchers::Matcher;
use jj_lib::merge::MergedTreeValue;
use jj_lib::merged_tree::{MergedTree, TreeDiffStream};
use jj_lib::object_id::ObjectId;
use jj_lib::repo::Repo;
use jj_lib::repo_path::{RepoPath, RepoPathBuf};
use jj_lib::settings::{ConfigResultExt as _, UserSettings};

View file

@ -4,12 +4,13 @@ use std::sync::Arc;
use futures::{StreamExt, TryStreamExt};
use itertools::Itertools;
use jj_lib::backend::{BackendError, FileId, MergedTreeId, ObjectId, TreeValue};
use jj_lib::backend::{BackendError, FileId, MergedTreeId, TreeValue};
use jj_lib::diff::{find_line_ranges, Diff, DiffHunk};
use jj_lib::files::{self, ContentHunk, MergeResult};
use jj_lib::matchers::Matcher;
use jj_lib::merge::Merge;
use jj_lib::merged_tree::{MergedTree, MergedTreeBuilder};
use jj_lib::object_id::ObjectId;
use jj_lib::repo_path::{RepoPath, RepoPathBuf};
use jj_lib::store::Store;
use pollster::FutureExt;

View file

@ -15,7 +15,7 @@
use std::io;
use itertools::Itertools as _;
use jj_lib::backend::ObjectId;
use jj_lib::object_id::ObjectId;
use jj_lib::op_store::{OperationId, OperationMetadata};
use jj_lib::operation::Operation;
use jj_lib::repo::ReadonlyRepo;

View file

@ -14,7 +14,8 @@
use std::path::Path;
use itertools::Itertools as _;
use jj_lib::backend::{CommitId, ObjectId as _};
use jj_lib::backend::CommitId;
use jj_lib::object_id::ObjectId as _;
use crate::common::TestEnvironment;

View file

@ -26,75 +26,10 @@ use thiserror::Error;
use crate::content_hash::ContentHash;
use crate::merge::Merge;
use crate::object_id::{id_type, ObjectId};
use crate::repo_path::{RepoPath, RepoPathComponent, RepoPathComponentBuf};
use crate::signing::SignResult;
pub trait ObjectId {
fn new(value: Vec<u8>) -> Self;
fn object_type(&self) -> String;
fn from_bytes(bytes: &[u8]) -> Self;
fn as_bytes(&self) -> &[u8];
fn to_bytes(&self) -> Vec<u8>;
fn from_hex(hex: &str) -> Self;
fn hex(&self) -> String;
}
macro_rules! id_type {
($vis:vis $name:ident) => {
content_hash! {
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
$vis struct $name(Vec<u8>);
}
$crate::backend::impl_id_type!($name);
};
}
macro_rules! impl_id_type {
($name:ident) => {
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()
}
}
impl crate::backend::ObjectId for $name {
fn new(value: Vec<u8>) -> Self {
Self(value)
}
fn object_type(&self) -> String {
stringify!($name)
.strip_suffix("Id")
.unwrap()
.to_ascii_lowercase()
.to_string()
}
fn from_bytes(bytes: &[u8]) -> Self {
Self(bytes.to_vec())
}
fn as_bytes(&self) -> &[u8] {
&self.0
}
fn to_bytes(&self) -> Vec<u8> {
self.0.clone()
}
fn from_hex(hex: &str) -> Self {
Self(hex::decode(hex).unwrap())
}
fn hex(&self) -> String {
hex::encode(&self.0)
}
}
};
}
pub(crate) use {id_type, impl_id_type};
id_type!(pub CommitId);
id_type!(pub ChangeId);
id_type!(pub TreeId);

View file

@ -26,8 +26,9 @@ use super::entry::{
};
use super::readonly::ReadonlyIndexSegment;
use super::rev_walk::RevWalk;
use crate::backend::{ChangeId, CommitId, ObjectId};
use crate::backend::{ChangeId, CommitId};
use crate::index::{HexPrefix, Index, PrefixResolution};
use crate::object_id::ObjectId;
use crate::revset::{ResolvedExpression, Revset, RevsetEvaluationError};
use crate::store::Store;
use crate::{default_revset_engine, hex_util};

View file

@ -20,7 +20,8 @@ use std::hash::{Hash, Hasher};
use smallvec::SmallVec;
use super::composite::{CompositeIndex, IndexSegment};
use crate::backend::{ChangeId, CommitId, ObjectId};
use crate::backend::{ChangeId, CommitId};
use crate::object_id::ObjectId;
/// Global index position.
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]

View file

@ -43,8 +43,9 @@ mod tests {
use super::entry::SmallIndexPositionsVec;
use super::mutable::MutableIndexSegment;
use super::*;
use crate::backend::{ChangeId, CommitId, ObjectId};
use crate::backend::{ChangeId, CommitId};
use crate::index::{HexPrefix, Index, PrefixResolution};
use crate::object_id::ObjectId;
/// Generator of unique 16-byte ChangeId excluding root id
fn change_id_generator() -> impl FnMut() -> ChangeId {

View file

@ -32,10 +32,11 @@ use tempfile::NamedTempFile;
use super::composite::{AsCompositeIndex, CompositeIndex, IndexSegment};
use super::entry::{IndexPosition, LocalPosition, SmallIndexPositionsVec};
use super::readonly::{DefaultReadonlyIndex, ReadonlyIndexSegment};
use crate::backend::{ChangeId, CommitId, ObjectId};
use crate::backend::{ChangeId, CommitId};
use crate::commit::Commit;
use crate::file_util::persist_content_addressed_temp_file;
use crate::index::{HexPrefix, Index, MutableIndex, PrefixResolution, ReadonlyIndex};
use crate::object_id::ObjectId;
use crate::revset::{ResolvedExpression, Revset, RevsetEvaluationError};
use crate::store::Store;

View file

@ -29,9 +29,10 @@ use thiserror::Error;
use super::composite::{AsCompositeIndex, CompositeIndex, IndexSegment};
use super::entry::{IndexPosition, LocalPosition, SmallIndexPositionsVec};
use super::mutable::DefaultMutableIndex;
use crate::backend::{ChangeId, CommitId, ObjectId};
use crate::backend::{ChangeId, CommitId};
use crate::default_revset_engine;
use crate::index::{HexPrefix, Index, MutableIndex, PrefixResolution, ReadonlyIndex};
use crate::object_id::ObjectId;
use crate::revset::{ResolvedExpression, Revset, RevsetEvaluationError};
use crate::store::Store;

View file

@ -27,13 +27,14 @@ use thiserror::Error;
use super::mutable::DefaultMutableIndex;
use super::readonly::{DefaultReadonlyIndex, ReadonlyIndexLoadError, ReadonlyIndexSegment};
use crate::backend::{BackendError, BackendInitError, CommitId, ObjectId};
use crate::backend::{BackendError, BackendInitError, CommitId};
use crate::commit::CommitByCommitterTimestamp;
use crate::dag_walk;
use crate::file_util::{persist_content_addressed_temp_file, IoResultExt as _, PathError};
use crate::index::{
Index, IndexReadError, IndexStore, IndexWriteError, MutableIndex, ReadonlyIndex,
};
use crate::object_id::ObjectId;
use crate::op_store::{OpStoreError, OperationId};
use crate::operation::Operation;
use crate::store::Store;

View file

@ -999,8 +999,9 @@ fn has_diff_from_parent(
#[cfg(test)]
mod tests {
use super::*;
use crate::backend::{ChangeId, CommitId, ObjectId};
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 {

View file

@ -26,9 +26,10 @@ use itertools::Itertools;
use tempfile::NamedTempFile;
use thiserror::Error;
use crate::backend::{BackendError, CommitId, ObjectId};
use crate::backend::{BackendError, CommitId};
use crate::commit::Commit;
use crate::git_backend::GitBackend;
use crate::object_id::ObjectId;
use crate::op_store::{RefTarget, RefTargetOptionExt, RemoteRef, RemoteRefState};
use crate::refs::BranchPushUpdate;
use crate::repo::{MutableRepo, Repo};

View file

@ -32,12 +32,13 @@ use thiserror::Error;
use crate::backend::{
make_root_commit, Backend, BackendError, BackendInitError, BackendLoadError, BackendResult,
ChangeId, Commit, CommitId, Conflict, ConflictId, ConflictTerm, FileId, MergedTreeId,
MillisSinceEpoch, ObjectId, SecureSig, Signature, SigningFn, SymlinkId, Timestamp, Tree,
TreeId, TreeValue,
MillisSinceEpoch, SecureSig, Signature, SigningFn, SymlinkId, Timestamp, Tree, TreeId,
TreeValue,
};
use crate::file_util::{IoResultExt as _, PathError};
use crate::lock::FileLock;
use crate::merge::{Merge, MergeBuilder};
use crate::object_id::ObjectId;
use crate::repo_path::{RepoPath, RepoPathComponentBuf};
use crate::settings::UserSettings;
use crate::stacked_table::{

View file

@ -21,9 +21,10 @@ use std::rc::Rc;
use itertools::Itertools as _;
use once_cell::unsync::OnceCell;
use crate::backend::{ChangeId, CommitId, ObjectId};
use crate::backend::{ChangeId, CommitId};
use crate::hex_util;
use crate::index::{HexPrefix, PrefixResolution};
use crate::object_id::ObjectId;
use crate::repo::Repo;
use crate::revset::{DefaultSymbolResolver, RevsetExpression};
@ -445,7 +446,8 @@ fn unwrap_as_short_key<const N: usize>(key_bytes: &[u8]) -> &[u8; N] {
#[cfg(test)]
mod tests {
use super::*;
use crate::backend::{ChangeId, ObjectId};
use crate::backend::ChangeId;
use crate::object_id::ObjectId;
#[derive(Clone, Copy, Eq, PartialEq)]
struct Position(usize);

View file

@ -20,8 +20,9 @@ use std::sync::Arc;
use thiserror::Error;
use crate::backend::{CommitId, ObjectId};
use crate::backend::CommitId;
use crate::commit::Commit;
use crate::object_id::ObjectId;
use crate::op_store::OperationId;
use crate::operation::Operation;
use crate::revset::{ResolvedExpression, Revset, RevsetEvaluationError};

View file

@ -47,6 +47,7 @@ pub mod lock;
pub mod matchers;
pub mod merge;
pub mod merged_tree;
pub mod object_id;
pub mod op_heads_store;
pub mod op_store;
pub mod op_walk;

View file

@ -28,12 +28,13 @@ use tempfile::NamedTempFile;
use crate::backend::{
make_root_commit, Backend, BackendError, BackendResult, ChangeId, Commit, CommitId, Conflict,
ConflictId, ConflictTerm, FileId, MergedTreeId, MillisSinceEpoch, ObjectId, SecureSig,
Signature, SigningFn, SymlinkId, Timestamp, Tree, TreeId, TreeValue,
ConflictId, ConflictTerm, FileId, MergedTreeId, MillisSinceEpoch, SecureSig, Signature,
SigningFn, SymlinkId, Timestamp, Tree, TreeId, TreeValue,
};
use crate::content_hash::blake2b_hash;
use crate::file_util::persist_content_addressed_temp_file;
use crate::merge::MergeBuilder;
use crate::object_id::ObjectId;
use crate::repo_path::{RepoPath, RepoPathComponentBuf};
const COMMIT_ID_LENGTH: usize = 64;

View file

@ -42,7 +42,7 @@ use thiserror::Error;
use tracing::{instrument, trace_span};
use crate::backend::{
BackendError, FileId, MergedTreeId, MillisSinceEpoch, ObjectId, SymlinkId, TreeId, TreeValue,
BackendError, FileId, MergedTreeId, MillisSinceEpoch, SymlinkId, TreeId, TreeValue,
};
use crate::commit::Commit;
use crate::conflicts::{self, materialize_tree_value, MaterializedTreeValue};
@ -56,6 +56,7 @@ use crate::matchers::{
};
use crate::merge::{Merge, MergeBuilder, MergedTreeValue};
use crate::merged_tree::{MergedTree, MergedTreeBuilder};
use crate::object_id::ObjectId;
use crate::op_store::{OperationId, WorkspaceId};
use crate::repo_path::{RepoPath, RepoPathBuf, RepoPathComponent};
use crate::settings::HumanByteSize;

View file

@ -28,8 +28,9 @@ use itertools::Itertools;
use smallvec::{smallvec_inline, SmallVec};
use crate::backend;
use crate::backend::{BackendError, FileId, ObjectId, TreeId, TreeValue};
use crate::backend::{BackendError, FileId, TreeId, TreeValue};
use crate::content_hash::ContentHash;
use crate::object_id::ObjectId;
use crate::repo_path::RepoPath;
use crate::store::Store;
use crate::tree::Tree;

81
lib/src/object_id.rs Normal file
View file

@ -0,0 +1,81 @@
// Copyright 2020-2024 The Jujutsu Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#![allow(missing_docs)]
pub trait ObjectId {
fn new(value: Vec<u8>) -> Self;
fn object_type(&self) -> String;
fn from_bytes(bytes: &[u8]) -> Self;
fn as_bytes(&self) -> &[u8];
fn to_bytes(&self) -> Vec<u8>;
fn from_hex(hex: &str) -> Self;
fn hex(&self) -> String;
}
macro_rules! id_type {
($vis:vis $name:ident) => {
content_hash! {
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
$vis struct $name(Vec<u8>);
}
$crate::object_id::impl_id_type!($name);
};
}
macro_rules! impl_id_type {
($name:ident) => {
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()
}
}
impl crate::object_id::ObjectId for $name {
fn new(value: Vec<u8>) -> Self {
Self(value)
}
fn object_type(&self) -> String {
stringify!($name)
.strip_suffix("Id")
.unwrap()
.to_ascii_lowercase()
.to_string()
}
fn from_bytes(bytes: &[u8]) -> Self {
Self(bytes.to_vec())
}
fn as_bytes(&self) -> &[u8] {
&self.0
}
fn to_bytes(&self) -> Vec<u8> {
self.0.clone()
}
fn from_hex(hex: &str) -> Self {
Self(hex::decode(hex).unwrap())
}
fn hex(&self) -> String {
hex::encode(&self.0)
}
}
};
}
pub(crate) use {id_type, impl_id_type};

View file

@ -22,9 +22,10 @@ use itertools::Itertools as _;
use once_cell::sync::Lazy;
use thiserror::Error;
use crate::backend::{id_type, CommitId, ObjectId, Timestamp};
use crate::backend::{CommitId, Timestamp};
use crate::content_hash::ContentHash;
use crate::merge::Merge;
use crate::object_id::{id_type, ObjectId};
content_hash! {
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]

View file

@ -22,8 +22,8 @@ use std::sync::Arc;
use itertools::Itertools as _;
use thiserror::Error;
use crate::backend::ObjectId as _;
use crate::index::HexPrefix;
use crate::object_id::ObjectId as _;
use crate::op_heads_store::{OpHeadResolutionError, OpHeadsStore};
use crate::op_store::{OpStore, OpStoreError, OpStoreResult, OperationId};
use crate::operation::Operation;

View file

@ -205,7 +205,7 @@ pub fn classify_branch_push_action(targets: TrackingRefPair) -> BranchPushAction
#[cfg(test)]
mod tests {
use super::*;
use crate::backend::ObjectId;
use crate::object_id::ObjectId;
use crate::op_store::RemoteRefState;
fn new_remote_ref(target: RefTarget) -> RemoteRef {

View file

@ -30,7 +30,7 @@ use tracing::instrument;
use self::dirty_cell::DirtyCell;
use crate::backend::{
Backend, BackendError, BackendInitError, BackendLoadError, BackendResult, ChangeId, CommitId,
MergedTreeId, ObjectId, SigningFn,
MergedTreeId, SigningFn,
};
use crate::commit::{Commit, CommitByCommitterTimestamp};
use crate::commit_builder::CommitBuilder;
@ -40,6 +40,7 @@ use crate::file_util::{IoResultExt as _, PathError};
use crate::git_backend::GitBackend;
use crate::index::{HexPrefix, Index, IndexStore, MutableIndex, PrefixResolution, ReadonlyIndex};
use crate::local_backend::LocalBackend;
use crate::object_id::ObjectId;
use crate::op_heads_store::{self, OpHeadResolutionError, OpHeadsStore};
use crate::op_store::{
OpStore, OpStoreError, OperationId, RefTarget, RemoteRef, RemoteRefState, WorkspaceId,

View file

@ -296,7 +296,7 @@ mod tests {
use renderdag::{Ancestor, GraphRowRenderer, Renderer as _};
use super::*;
use crate::backend::ObjectId;
use crate::object_id::ObjectId;
fn id(c: char) -> CommitId {
let d = u8::try_from(c).unwrap();

View file

@ -22,12 +22,13 @@ use itertools::Itertools;
use pollster::FutureExt;
use tracing::instrument;
use crate::backend::{BackendError, BackendResult, CommitId, MergedTreeId, ObjectId};
use crate::backend::{BackendError, BackendResult, CommitId, MergedTreeId};
use crate::commit::Commit;
use crate::dag_walk;
use crate::index::Index;
use crate::matchers::{Matcher, Visit};
use crate::merged_tree::{MergedTree, MergedTreeBuilder};
use crate::object_id::ObjectId;
use crate::op_store::RefTarget;
use crate::repo::{MutableRepo, Repo};
use crate::repo_path::RepoPath;

View file

@ -21,9 +21,10 @@ use chrono::DateTime;
use rand::prelude::*;
use rand_chacha::ChaCha20Rng;
use crate::backend::{ChangeId, Commit, ObjectId, Signature, Timestamp};
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)]

View file

@ -18,8 +18,8 @@ use std::fmt::{Debug, Formatter};
use std::fs;
use std::path::{Path, PathBuf};
use crate::backend::ObjectId;
use crate::lock::FileLock;
use crate::object_id::ObjectId;
use crate::op_heads_store::{OpHeadsStore, OpHeadsStoreLock};
use crate::op_store::OperationId;

View file

@ -24,10 +24,11 @@ use prost::Message;
use tempfile::NamedTempFile;
use thiserror::Error;
use crate::backend::{CommitId, MillisSinceEpoch, ObjectId, Timestamp};
use crate::backend::{CommitId, MillisSinceEpoch, Timestamp};
use crate::content_hash::blake2b_hash;
use crate::file_util::persist_content_addressed_temp_file;
use crate::merge::Merge;
use crate::object_id::ObjectId;
use crate::op_store::{
OpStore, OpStoreError, OpStoreResult, Operation, OperationId, OperationMetadata, RefTarget,
RemoteRef, RemoteRefState, RemoteView, View, ViewId, WorkspaceId,
@ -528,8 +529,9 @@ mod tests {
use maplit::{btreemap, hashmap, hashset};
use super::*;
use crate::backend::{CommitId, MillisSinceEpoch, ObjectId, Timestamp};
use crate::backend::{CommitId, MillisSinceEpoch, Timestamp};
use crate::content_hash::blake2b_hash;
use crate::object_id::ObjectId;
use crate::op_store::{OperationMetadata, RefTarget, WorkspaceId};
fn create_view() -> View {

View file

@ -24,12 +24,12 @@ use thiserror::Error;
use tracing::instrument;
use crate::backend::{
BackendError, ConflictId, FileId, ObjectId, TreeEntriesNonRecursiveIterator, TreeEntry, TreeId,
TreeValue,
BackendError, ConflictId, FileId, TreeEntriesNonRecursiveIterator, TreeEntry, TreeId, TreeValue,
};
use crate::files::MergeResult;
use crate::matchers::{EverythingMatcher, Matcher};
use crate::merge::{trivial_merge, Merge, MergedTreeValue};
use crate::object_id::ObjectId;
use crate::repo_path::{RepoPath, RepoPathBuf, RepoPathComponent, RepoPathComponentsIter};
use crate::store::Store;
use crate::{backend, files};

View file

@ -12,9 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use jj_lib::backend::{ChangeId, MillisSinceEpoch, ObjectId, Signature, Timestamp};
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;

View file

@ -20,9 +20,7 @@ use std::{fs, thread};
use assert_matches::assert_matches;
use git2::Oid;
use itertools::Itertools;
use jj_lib::backend::{
BackendError, ChangeId, CommitId, MillisSinceEpoch, ObjectId, Signature, Timestamp,
};
use jj_lib::backend::{BackendError, ChangeId, CommitId, MillisSinceEpoch, Signature, Timestamp};
use jj_lib::commit::Commit;
use jj_lib::commit_builder::CommitBuilder;
use jj_lib::git;
@ -31,6 +29,7 @@ use jj_lib::git::{
GitRefUpdate, RefName, SubmoduleConfig,
};
use jj_lib::git_backend::GitBackend;
use jj_lib::object_id::ObjectId;
use jj_lib::op_store::{BranchTarget, RefTarget, RemoteRef, RemoteRefState};
use jj_lib::refs::BranchPushUpdate;
use jj_lib::repo::{MutableRepo, ReadonlyRepo, Repo};

View file

@ -13,10 +13,11 @@
// limitations under the License.
use itertools::Itertools;
use jj_lib::backend::{CommitId, MillisSinceEpoch, ObjectId, Signature, Timestamp};
use jj_lib::backend::{CommitId, MillisSinceEpoch, Signature, Timestamp};
use jj_lib::id_prefix::IdPrefixContext;
use jj_lib::index::HexPrefix;
use jj_lib::index::PrefixResolution::{AmbiguousMatch, NoMatch, SingleMatch};
use jj_lib::object_id::ObjectId;
use jj_lib::repo::Repo;
use jj_lib::revset::RevsetExpression;
use testutils::{TestRepo, TestRepoBackend};

View file

@ -16,7 +16,7 @@ use std::fs;
use std::sync::Arc;
use assert_matches::assert_matches;
use jj_lib::backend::{CommitId, ObjectId as _};
use jj_lib::backend::CommitId;
use jj_lib::commit::Commit;
use jj_lib::commit_builder::CommitBuilder;
use jj_lib::default_index::{
@ -24,6 +24,7 @@ use jj_lib::default_index::{
DefaultMutableIndex, DefaultReadonlyIndex, IndexPosition,
};
use jj_lib::index::Index as _;
use jj_lib::object_id::ObjectId as _;
use jj_lib::repo::{MutableRepo, ReadonlyRepo, Repo};
use jj_lib::settings::UserSettings;
use testutils::test_backend::TestBackend;

View file

@ -26,11 +26,12 @@ use std::path::Path;
use std::sync::Arc;
use itertools::Itertools;
use jj_lib::backend::{MergedTreeId, ObjectId, TreeId, TreeValue};
use jj_lib::backend::{MergedTreeId, TreeId, TreeValue};
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};

View file

@ -18,7 +18,8 @@ use std::sync::Arc;
use assert_matches::assert_matches;
use itertools::Itertools as _;
use jj_lib::backend::{CommitId, ObjectId};
use jj_lib::backend::CommitId;
use jj_lib::object_id::ObjectId;
use jj_lib::op_walk::{self, OpsetEvaluationError, OpsetResolutionError};
use jj_lib::operation::Operation;
use jj_lib::repo::{ReadonlyRepo, Repo};

View file

@ -21,11 +21,12 @@ use std::path::Path;
use assert_matches::assert_matches;
use itertools::Itertools;
use jj_lib::backend::{ChangeId, CommitId, MillisSinceEpoch, ObjectId, Signature, Timestamp};
use jj_lib::backend::{ChangeId, CommitId, MillisSinceEpoch, Signature, Timestamp};
use jj_lib::commit::Commit;
use jj_lib::git;
use jj_lib::git_backend::GitBackend;
use jj_lib::index::{HexPrefix, PrefixResolution};
use jj_lib::object_id::ObjectId;
use jj_lib::op_store::{RefTarget, RemoteRef, RemoteRefState, WorkspaceId};
use jj_lib::repo::Repo;
use jj_lib::repo_path::RepoPath;

View file

@ -22,13 +22,14 @@ use std::sync::{Arc, Once};
use itertools::Itertools;
use jj_lib::backend::{
self, Backend, BackendInitError, ChangeId, CommitId, FileId, MergedTreeId, MillisSinceEpoch,
ObjectId, Signature, Timestamp, TreeValue,
Signature, Timestamp, TreeValue,
};
use jj_lib::commit::Commit;
use jj_lib::commit_builder::CommitBuilder;
use jj_lib::git_backend::GitBackend;
use jj_lib::local_backend::LocalBackend;
use jj_lib::merged_tree::MergedTree;
use jj_lib::object_id::ObjectId;
use jj_lib::repo::{MutableRepo, ReadonlyRepo, Repo, RepoLoader, StoreFactories};
use jj_lib::repo_path::{RepoPath, RepoPathBuf};
use jj_lib::settings::UserSettings;

View file

@ -22,8 +22,9 @@ use std::sync::{Arc, Mutex, MutexGuard, OnceLock};
use async_trait::async_trait;
use jj_lib::backend::{
make_root_commit, Backend, BackendError, BackendResult, ChangeId, Commit, CommitId, Conflict,
ConflictId, FileId, ObjectId, SecureSig, SigningFn, SymlinkId, Tree, TreeId,
ConflictId, FileId, SecureSig, SigningFn, SymlinkId, Tree, TreeId,
};
use jj_lib::object_id::ObjectId;
use jj_lib::repo_path::{RepoPath, RepoPathBuf};
const HASH_LENGTH: usize = 10;