diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index 4c0ceafcb..ddf69bca3 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -2652,15 +2652,15 @@ pub fn edit_temp_file( } pub fn short_commit_hash(commit_id: &CommitId) -> String { - commit_id.hex()[0..12].to_string() + format!("{commit_id:.12}") } pub fn short_change_hash(change_id: &ChangeId) -> String { - change_id.reverse_hex()[0..12].to_string() + format!("{change_id:.12}") } pub fn short_operation_hash(operation_id: &OperationId) -> String { - operation_id.hex()[0..12].to_string() + format!("{operation_id:.12}") } /// Wrapper around a `DiffEditor` to conditionally start interactive session. diff --git a/cli/src/commands/debug/revset.rs b/cli/src/commands/debug/revset.rs index f6ee8142e..55c309e2b 100644 --- a/cli/src/commands/debug/revset.rs +++ b/cli/src/commands/debug/revset.rs @@ -15,7 +15,6 @@ use std::fmt::Debug; use std::io::Write as _; -use jj_lib::object_id::ObjectId; use jj_lib::revset; use jj_lib::revset::RevsetDiagnostics; @@ -69,7 +68,7 @@ pub fn cmd_debug_revset( writeln!(ui.stdout(), "-- Commit IDs:")?; for commit_id in revset.iter() { - writeln!(ui.stdout(), "{}", commit_id.hex())?; + writeln!(ui.stdout(), "{commit_id}")?; } Ok(()) } diff --git a/cli/src/diff_util.rs b/cli/src/diff_util.rs index 495e06ae4..88ddefba2 100644 --- a/cli/src/diff_util.rs +++ b/cli/src/diff_util.rs @@ -850,7 +850,7 @@ fn diff_content(path: &RepoPath, value: MaterializedTreeValue) -> io::Result Ok(FileContent { is_binary: false, - contents: format!("Git submodule checked out at {}", id.hex()).into_bytes(), + contents: format!("Git submodule checked out at {id}").into_bytes(), }), // TODO: are we sure this is never binary? MaterializedTreeValue::FileConflict { diff --git a/cli/src/merge_tools/builtin.rs b/cli/src/merge_tools/builtin.rs index 8631a567c..1a5fdb8ef 100644 --- a/cli/src/merge_tools/builtin.rs +++ b/cli/src/merge_tools/builtin.rs @@ -37,7 +37,7 @@ pub enum BuiltinToolError { Record(#[from] scm_record::RecordError), #[error(transparent)] ReadFileBackend(BackendError), - #[error("Failed to read file {path:?} with ID {id}", id = id.hex())] + #[error("Failed to read file {path:?} with ID {id}")] ReadFileIo { path: RepoPathBuf, id: FileId, diff --git a/lib/src/backend.rs b/lib/src/backend.rs index c0031cc57..285cdd129 100644 --- a/lib/src/backend.rs +++ b/lib/src/backend.rs @@ -39,17 +39,17 @@ use crate::signing::SignResult; id_type!( /// Identifier for a [`Commit`] based on its content. When a commit is /// rewritten, its `CommitId` changes. - pub CommitId + pub CommitId { hex() } ); id_type!( /// Stable identifier for a [`Commit`]. Unlike the `CommitId`, the `ChangeId` /// follows the commit and is not updated when the commit is rewritten. - pub ChangeId + pub ChangeId { reverse_hex() } ); -id_type!(pub TreeId); -id_type!(pub FileId); -id_type!(pub SymlinkId); -id_type!(pub ConflictId); +id_type!(pub TreeId { hex() }); +id_type!(pub FileId { hex() }); +id_type!(pub SymlinkId { hex() }); +id_type!(pub ConflictId { hex() }); impl ChangeId { /// Returns the hex string representation of this ID, which uses `z-k` @@ -240,7 +240,10 @@ pub enum BackendError { hash: String, source: Box, }, - #[error("Error when reading file content for file {} with id {}", path.as_internal_file_string(), id.hex())] + #[error( + "Error when reading file content for file {path} with id {id}", + path = path.as_internal_file_string() + )] ReadFile { path: RepoPathBuf, id: FileId, diff --git a/lib/src/default_index/store.rs b/lib/src/default_index/store.rs index 8c516a0de..db348dc37 100644 --- a/lib/src/default_index/store.rs +++ b/lib/src/default_index/store.rs @@ -68,10 +68,7 @@ impl From for BackendInitError { #[derive(Debug, Error)] pub enum DefaultIndexStoreError { - #[error( - "Failed to associate commit index file with an operation {op_id}", - op_id = op_id.hex() - )] + #[error("Failed to associate commit index file with an operation {op_id}")] AssociateIndex { op_id: OperationId, source: io::Error, @@ -82,7 +79,7 @@ pub enum DefaultIndexStoreError { LoadIndex(ReadonlyIndexLoadError), #[error("Failed to write commit index file")] SaveIndex(#[source] io::Error), - #[error("Failed to index commits at operation {op_id}", op_id = op_id.hex())] + #[error("Failed to index commits at operation {op_id}")] IndexCommits { op_id: OperationId, source: BackendError, diff --git a/lib/src/git.rs b/lib/src/git.rs index b59a3c043..3c2699242 100644 --- a/lib/src/git.rs +++ b/lib/src/git.rs @@ -180,7 +180,7 @@ fn resolve_git_ref_to_commit_id( #[derive(Error, Debug)] pub enum GitImportError { - #[error("Failed to read Git HEAD target commit {id}", id=id.hex())] + #[error("Failed to read Git HEAD target commit {id}")] MissingHeadTarget { id: CommitId, #[source] diff --git a/lib/src/git_backend.rs b/lib/src/git_backend.rs index ce281819c..1f4e2e915 100644 --- a/lib/src/git_backend.rs +++ b/lib/src/git_backend.rs @@ -703,7 +703,7 @@ fn deserialize_extras(commit: &mut Commit, bytes: &[u8]) { /// Returns `RefEdit` that will create a ref in `refs/jj/keep` if not exist. /// Used for preventing GC of commits we create. fn to_no_gc_ref_update(id: &CommitId) -> gix::refs::transaction::RefEdit { - let name = format!("{NO_GC_REF_NAMESPACE}{}", id.hex()); + let name = format!("{NO_GC_REF_NAMESPACE}{id}"); let new = gix::refs::Target::Object(validate_git_object_id(id).unwrap()); let expected = gix::refs::transaction::PreviousValue::ExistingMustMatch(new.clone()); gix::refs::transaction::RefEdit { diff --git a/lib/src/merge.rs b/lib/src/merge.rs index 286dac1f4..7a3e00645 100644 --- a/lib/src/merge.rs +++ b/lib/src/merge.rs @@ -36,7 +36,6 @@ use crate::backend::TreeId; use crate::backend::TreeValue; use crate::content_hash::ContentHash; use crate::content_hash::DigestUpdate; -use crate::object_id::ObjectId; use crate::repo_path::RepoPath; use crate::store::Store; use crate::tree::Tree; @@ -665,25 +664,25 @@ fn describe_conflict_term(value: &TreeValue) -> String { id, executable: false, } => { - format!("file with id {}", id.hex()) + format!("file with id {id}") } TreeValue::File { id, executable: true, } => { - format!("executable file with id {}", id.hex()) + format!("executable file with id {id}") } TreeValue::Symlink(id) => { - format!("symlink with id {}", id.hex()) + format!("symlink with id {id}") } TreeValue::Tree(id) => { - format!("tree with id {}", id.hex()) + format!("tree with id {id}") } TreeValue::GitSubmodule(id) => { - format!("Git submodule with id {}", id.hex()) + format!("Git submodule with id {id}") } TreeValue::Conflict(id) => { - format!("Conflict with id {}", id.hex()) + format!("Conflict with id {id}") } } } diff --git a/lib/src/object_id.rs b/lib/src/object_id.rs index 061b68bf1..7756987d0 100644 --- a/lib/src/object_id.rs +++ b/lib/src/object_id.rs @@ -32,22 +32,22 @@ pub trait ObjectId { // ```no_run // id_type!( // /// My favorite id type. -// pub MyId +// pub MyId { hex() } // ); // ``` macro_rules! id_type { ( $(#[$attr:meta])* - $vis:vis $name:ident + $vis:vis $name:ident { $hex_method:ident() } ) => { $(#[$attr])* #[derive(ContentHash, PartialEq, Eq, PartialOrd, Ord, Clone, Hash)] $vis struct $name(Vec); - $crate::object_id::impl_id_type!($name); + $crate::object_id::impl_id_type!($name, $hex_method); }; } macro_rules! impl_id_type { - ($name:ident) => { + ($name:ident, $hex_method:ident) => { impl $name { pub fn new(value: Vec) -> Self { Self(value) @@ -73,10 +73,17 @@ macro_rules! impl_id_type { impl std::fmt::Debug for $name { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { + // TODO: should we use $hex_method here? f.debug_tuple(stringify!($name)).field(&self.hex()).finish() } } + impl std::fmt::Display for $name { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { + f.pad(&self.$hex_method()) + } + } + impl crate::object_id::ObjectId for $name { fn object_type(&self) -> String { stringify!($name) @@ -217,8 +224,20 @@ impl PrefixResolution { #[cfg(test)] mod tests { use super::*; + use crate::backend::ChangeId; use crate::backend::CommitId; + #[test] + fn test_display_object_id() { + let commit_id = CommitId::from_hex("deadbeef0123"); + assert_eq!(format!("{commit_id}"), "deadbeef0123"); + assert_eq!(format!("{commit_id:.6}"), "deadbe"); + + let change_id = ChangeId::from_hex("deadbeef0123"); + assert_eq!(format!("{change_id}"), "mlpmollkzyxw"); + assert_eq!(format!("{change_id:.6}"), "mlpmol"); + } + #[test] fn test_hex_prefix_prefixes() { let prefix = HexPrefix::new("").unwrap(); diff --git a/lib/src/op_store.rs b/lib/src/op_store.rs index 0c64e07e0..635b2ed69 100644 --- a/lib/src/op_store.rs +++ b/lib/src/op_store.rs @@ -63,8 +63,8 @@ impl WorkspaceId { } } -id_type!(pub ViewId); -id_type!(pub OperationId); +id_type!(pub ViewId { hex() }); +id_type!(pub OperationId { hex() }); #[derive(ContentHash, PartialEq, Eq, Hash, Clone, Debug)] pub struct RefTarget { diff --git a/lib/tests/test_revset.rs b/lib/tests/test_revset.rs index 4ee99e123..bdfa0f6ee 100644 --- a/lib/tests/test_revset.rs +++ b/lib/tests/test_revset.rs @@ -1071,7 +1071,7 @@ fn test_evaluate_expression_heads() { // Heads of a single commit is that commit assert_eq!( - resolve_commit_ids(mut_repo, &format!("heads({})", commit2.id().hex())), + resolve_commit_ids(mut_repo, &format!("heads({})", commit2.id())), vec![commit2.id().clone()] ); @@ -1079,7 +1079,7 @@ fn test_evaluate_expression_heads() { assert_eq!( resolve_commit_ids( mut_repo, - &format!("heads({} | {})", commit2.id().hex(), commit3.id().hex()) + &format!("heads({} | {})", commit2.id(), commit3.id()) ), vec![commit3.id().clone()] ); @@ -1089,7 +1089,7 @@ fn test_evaluate_expression_heads() { assert_eq!( resolve_commit_ids( mut_repo, - &format!("heads({} | {})", commit1.id().hex(), commit3.id().hex()) + &format!("heads({} | {})", commit1.id(), commit3.id()) ), vec![commit3.id().clone()] ); @@ -1098,7 +1098,7 @@ fn test_evaluate_expression_heads() { assert_eq!( resolve_commit_ids( mut_repo, - &format!("heads({} | {})", commit3.id().hex(), commit4.id().hex()) + &format!("heads({} | {})", commit3.id(), commit4.id()) ), vec![commit4.id().clone(), commit3.id().clone()] ); @@ -1135,7 +1135,7 @@ fn test_evaluate_expression_roots() { // Roots of a single commit is that commit assert_eq!( - resolve_commit_ids(mut_repo, &format!("roots({})", commit2.id().hex())), + resolve_commit_ids(mut_repo, &format!("roots({})", commit2.id())), vec![commit2.id().clone()] ); @@ -1143,7 +1143,7 @@ fn test_evaluate_expression_roots() { assert_eq!( resolve_commit_ids( mut_repo, - &format!("roots({} | {})", commit2.id().hex(), commit3.id().hex()) + &format!("roots({} | {})", commit2.id(), commit3.id()) ), vec![commit2.id().clone()] ); @@ -1153,7 +1153,7 @@ fn test_evaluate_expression_roots() { assert_eq!( resolve_commit_ids( mut_repo, - &format!("roots({} | {})", commit1.id().hex(), commit3.id().hex()) + &format!("roots({} | {})", commit1.id(), commit3.id()) ), vec![commit1.id().clone()] ); @@ -1195,53 +1195,44 @@ fn test_evaluate_expression_parents() { // Can find parents of a merge commit assert_eq!( - resolve_commit_ids(mut_repo, &format!("{}-", commit4.id().hex())), + resolve_commit_ids(mut_repo, &format!("{}-", commit4.id())), vec![commit3.id().clone(), commit2.id().clone()] ); // Parents of all commits in input are returned assert_eq!( - resolve_commit_ids( - mut_repo, - &format!("({} | {})-", commit2.id().hex(), commit3.id().hex()) - ), + resolve_commit_ids(mut_repo, &format!("({} | {})-", commit2.id(), commit3.id())), vec![commit1.id().clone(), root_commit.id().clone()] ); // Parents already in input set are returned assert_eq!( - resolve_commit_ids( - mut_repo, - &format!("({} | {})-", commit1.id().hex(), commit2.id().hex()) - ), + resolve_commit_ids(mut_repo, &format!("({} | {})-", commit1.id(), commit2.id())), vec![commit1.id().clone(), root_commit.id().clone()] ); // Parents shared among commits in input are not repeated assert_eq!( - resolve_commit_ids( - mut_repo, - &format!("({} | {})-", commit4.id().hex(), commit5.id().hex()) - ), + resolve_commit_ids(mut_repo, &format!("({} | {})-", commit4.id(), commit5.id())), vec![commit3.id().clone(), commit2.id().clone()] ); // Can find parents of parents, which may be optimized to single query assert_eq!( - resolve_commit_ids(mut_repo, &format!("{}--", commit4.id().hex())), + resolve_commit_ids(mut_repo, &format!("{}--", commit4.id())), vec![commit1.id().clone(), root_commit.id().clone()] ); assert_eq!( resolve_commit_ids( mut_repo, - &format!("({} | {})--", commit4.id().hex(), commit5.id().hex()) + &format!("({} | {})--", commit4.id(), commit5.id()) ), vec![commit1.id().clone(), root_commit.id().clone()] ); assert_eq!( resolve_commit_ids( mut_repo, - &format!("({} | {})--", commit4.id().hex(), commit2.id().hex()) + &format!("({} | {})--", commit4.id(), commit2.id()) ), vec![commit1.id().clone(), root_commit.id().clone()] ); @@ -1287,10 +1278,7 @@ fn test_evaluate_expression_children() { // Children of all commits in input are returned, including those already in the // input set assert_eq!( - resolve_commit_ids( - mut_repo, - &format!("({} | {})+", commit1.id().hex(), commit2.id().hex()) - ), + resolve_commit_ids(mut_repo, &format!("({} | {})+", commit1.id(), commit2.id())), vec![ commit4.id().clone(), commit3.id().clone(), @@ -1300,10 +1288,7 @@ fn test_evaluate_expression_children() { // Children shared among commits in input are not repeated assert_eq!( - resolve_commit_ids( - mut_repo, - &format!("({} | {})+", commit3.id().hex(), commit4.id().hex()) - ), + resolve_commit_ids(mut_repo, &format!("({} | {})+", commit3.id(), commit4.id())), vec![commit5.id().clone()] ); @@ -1313,7 +1298,7 @@ fn test_evaluate_expression_children() { vec![commit4.id().clone(), commit2.id().clone()] ); assert_eq!( - resolve_commit_ids(mut_repo, &format!("(root() | {})++", commit1.id().hex())), + resolve_commit_ids(mut_repo, &format!("(root() | {})++", commit1.id())), vec![ commit5.id().clone(), commit4.id().clone(), @@ -1324,7 +1309,7 @@ fn test_evaluate_expression_children() { assert_eq!( resolve_commit_ids( mut_repo, - &format!("({} | {})++", commit4.id().hex(), commit2.id().hex()) + &format!("({} | {})++", commit4.id(), commit2.id()) ), vec![commit6.id().clone(), commit5.id().clone()] ); @@ -1357,7 +1342,7 @@ fn test_evaluate_expression_ancestors() { // Can find ancestors of a specific commit. Commits reachable via multiple paths // are not repeated. assert_eq!( - resolve_commit_ids(mut_repo, &format!("::{}", commit4.id().hex())), + resolve_commit_ids(mut_repo, &format!("::{}", commit4.id())), vec![ commit4.id().clone(), commit3.id().clone(), @@ -1370,7 +1355,7 @@ fn test_evaluate_expression_ancestors() { // Can find ancestors of parents or parents of ancestors, which may be optimized // to single query assert_eq!( - resolve_commit_ids(mut_repo, &format!("::({}-)", commit4.id().hex()),), + resolve_commit_ids(mut_repo, &format!("::({}-)", commit4.id())), vec![ commit3.id().clone(), commit2.id().clone(), @@ -1381,7 +1366,7 @@ fn test_evaluate_expression_ancestors() { assert_eq!( resolve_commit_ids( mut_repo, - &format!("(::({}|{}))-", commit3.id().hex(), commit2.id().hex()), + &format!("(::({}|{}))-", commit3.id(), commit2.id()), ), vec![ commit2.id().clone(), @@ -1392,7 +1377,7 @@ fn test_evaluate_expression_ancestors() { assert_eq!( resolve_commit_ids( mut_repo, - &format!("::(({}|{})-)", commit3.id().hex(), commit2.id().hex()), + &format!("::(({}|{})-)", commit3.id(), commit2.id()), ), vec![ commit2.id().clone(), @@ -1403,15 +1388,15 @@ fn test_evaluate_expression_ancestors() { // Can find last n ancestors of a commit assert_eq!( - resolve_commit_ids(mut_repo, &format!("ancestors({}, 0)", commit2.id().hex())), + resolve_commit_ids(mut_repo, &format!("ancestors({}, 0)", commit2.id())), vec![] ); assert_eq!( - resolve_commit_ids(mut_repo, &format!("ancestors({}, 1)", commit3.id().hex())), + resolve_commit_ids(mut_repo, &format!("ancestors({}, 1)", commit3.id())), vec![commit3.id().clone()] ); assert_eq!( - resolve_commit_ids(mut_repo, &format!("ancestors({}, 3)", commit3.id().hex())), + resolve_commit_ids(mut_repo, &format!("ancestors({}, 3)", commit3.id())), vec![ commit3.id().clone(), commit2.id().clone(), @@ -1440,28 +1425,19 @@ fn test_evaluate_expression_range() { // Linear range assert_eq!( - resolve_commit_ids( - mut_repo, - &format!("{}..{}", commit1.id().hex(), commit3.id().hex()) - ), + resolve_commit_ids(mut_repo, &format!("{}..{}", commit1.id(), commit3.id())), vec![commit3.id().clone(), commit2.id().clone()] ); // Empty range (descendant first) assert_eq!( - resolve_commit_ids( - mut_repo, - &format!("{}..{}", commit3.id().hex(), commit1.id().hex()) - ), + resolve_commit_ids(mut_repo, &format!("{}..{}", commit3.id(), commit1.id())), vec![] ); // Range including a merge assert_eq!( - resolve_commit_ids( - mut_repo, - &format!("{}..{}", commit1.id().hex(), commit4.id().hex()) - ), + resolve_commit_ids(mut_repo, &format!("{}..{}", commit1.id(), commit4.id())), vec![ commit4.id().clone(), commit3.id().clone(), @@ -1471,31 +1447,25 @@ fn test_evaluate_expression_range() { // Range including merge ancestors: commit4-- == root | commit2 assert_eq!( - resolve_commit_ids( - mut_repo, - &format!("{}--..{}", commit4.id().hex(), commit3.id().hex()) - ), + resolve_commit_ids(mut_repo, &format!("{}--..{}", commit4.id(), commit3.id())), vec![commit3.id().clone()] ); // Sibling commits assert_eq!( - resolve_commit_ids( - mut_repo, - &format!("{}..{}", commit2.id().hex(), commit3.id().hex()) - ), + resolve_commit_ids(mut_repo, &format!("{}..{}", commit2.id(), commit3.id())), vec![commit3.id().clone()] ); // Left operand defaults to root() assert_eq!( - resolve_commit_ids(mut_repo, &format!("..{}", commit2.id().hex())), + resolve_commit_ids(mut_repo, &format!("..{}", commit2.id())), vec![commit2.id().clone(), commit1.id().clone()] ); // Right operand defaults to visible_heads() assert_eq!( - resolve_commit_ids(mut_repo, &format!("{}..", commit2.id().hex())), + resolve_commit_ids(mut_repo, &format!("{}..", commit2.id())), vec![commit4.id().clone(), commit3.id().clone()] ); @@ -1534,10 +1504,7 @@ fn test_evaluate_expression_dag_range() { // Linear range assert_eq!( - resolve_commit_ids( - mut_repo, - &format!("{}::{}", root_commit_id.hex(), commit2.id().hex()) - ), + resolve_commit_ids(mut_repo, &format!("{}::{}", root_commit_id, commit2.id())), vec![ commit2.id().clone(), commit1.id().clone(), @@ -1547,16 +1514,13 @@ fn test_evaluate_expression_dag_range() { // Empty range assert_eq!( - resolve_commit_ids( - mut_repo, - &format!("{}::{}", commit2.id().hex(), commit4.id().hex()) - ), + resolve_commit_ids(mut_repo, &format!("{}::{}", commit2.id(), commit4.id())), vec![] ); // Empty root assert_eq!( - resolve_commit_ids(mut_repo, &format!("none()::{}", commit5.id().hex())), + resolve_commit_ids(mut_repo, &format!("none()::{}", commit5.id())), vec![], ); @@ -1564,12 +1528,7 @@ fn test_evaluate_expression_dag_range() { assert_eq!( resolve_commit_ids( mut_repo, - &format!( - "({}|{})::{}", - commit1.id().hex(), - commit2.id().hex(), - commit3.id().hex() - ) + &format!("({}|{})::{}", commit1.id(), commit2.id(), commit3.id()) ), vec![ commit3.id().clone(), @@ -1580,10 +1539,7 @@ fn test_evaluate_expression_dag_range() { // Including a merge assert_eq!( - resolve_commit_ids( - mut_repo, - &format!("{}::{}", commit1.id().hex(), commit5.id().hex()) - ), + resolve_commit_ids(mut_repo, &format!("{}::{}", commit1.id(), commit5.id())), vec![ commit5.id().clone(), commit4.id().clone(), @@ -1595,10 +1551,7 @@ fn test_evaluate_expression_dag_range() { // Including a merge, but ancestors only from one side assert_eq!( - resolve_commit_ids( - mut_repo, - &format!("{}::{}", commit2.id().hex(), commit5.id().hex()) - ), + resolve_commit_ids(mut_repo, &format!("{}::{}", commit2.id(), commit5.id())), vec![ commit5.id().clone(), commit3.id().clone(), @@ -1649,11 +1602,7 @@ fn test_evaluate_expression_connected() { assert_eq!( resolve_commit_ids( mut_repo, - &format!( - "connected({} | {})", - root_commit_id.hex(), - commit2.id().hex() - ) + &format!("connected({} | {})", root_commit_id, commit2.id()) ), vec![commit2.id().clone(), commit1.id().clone(), root_commit_id] ); @@ -1662,7 +1611,7 @@ fn test_evaluate_expression_connected() { assert_eq!( resolve_commit_ids( mut_repo, - &format!("connected({} | {})", commit2.id().hex(), commit4.id().hex()) + &format!("connected({} | {})", commit2.id(), commit4.id()) ), vec![commit4.id().clone(), commit2.id().clone()] ); @@ -1671,7 +1620,7 @@ fn test_evaluate_expression_connected() { assert_eq!( resolve_commit_ids( mut_repo, - &format!("connected({} | {})", commit1.id().hex(), commit5.id().hex()) + &format!("connected({} | {})", commit1.id(), commit5.id()) ), vec![ commit5.id().clone(), @@ -1686,7 +1635,7 @@ fn test_evaluate_expression_connected() { assert_eq!( resolve_commit_ids( mut_repo, - &format!("connected({} | {})", commit2.id().hex(), commit5.id().hex()) + &format!("connected({} | {})", commit2.id(), commit5.id()) ), vec![ commit5.id().clone(), @@ -1748,8 +1697,8 @@ fn test_evaluate_expression_reachable() { mut_repo, &format!( "reachable({}, all() ~ ::{})", - graph1commit2.id().hex(), - graph1commit1.id().hex() + graph1commit2.id(), + graph1commit1.id() ) ), vec![graph1commit3.id().clone(), graph1commit2.id().clone(),] @@ -1759,8 +1708,8 @@ fn test_evaluate_expression_reachable() { mut_repo, &format!( "reachable({}, all() ~ ::{})", - graph1commit2.id().hex(), - graph1commit3.id().hex() + graph1commit2.id(), + graph1commit3.id() ) ), vec![] @@ -1774,7 +1723,7 @@ fn test_evaluate_expression_reachable() { assert_eq!( resolve_commit_ids( mut_repo, - &format!("reachable({}, all() ~ root())", commit.id().hex()) + &format!("reachable({}, all() ~ root())", commit.id()) ), vec![ graph1commit3.id().clone(), @@ -1793,7 +1742,7 @@ fn test_evaluate_expression_reachable() { assert_eq!( resolve_commit_ids( mut_repo, - &format!("reachable({}, all() ~ root())", commit.id().hex()) + &format!("reachable({}, all() ~ root())", commit.id()) ), vec![ graph2commit3.id().clone(), @@ -1820,7 +1769,7 @@ fn test_evaluate_expression_reachable() { assert_eq!( resolve_commit_ids( mut_repo, - &format!("reachable({}, all() ~ root())", commit.id().hex()) + &format!("reachable({}, all() ~ root())", commit.id()) ), vec![ graph3commit7.id().clone(), @@ -1842,8 +1791,8 @@ fn test_evaluate_expression_reachable() { mut_repo, &format!( "reachable({}, all() ~ ::{})", - graph3commit4.id().hex(), - graph3commit5.id().hex() + graph3commit4.id(), + graph3commit5.id() ) ), vec![ @@ -1902,7 +1851,7 @@ fn test_evaluate_expression_descendants() { // Can find descendants of a specific commit assert_eq!( - resolve_commit_ids(mut_repo, &format!("{}::", commit2.id().hex())), + resolve_commit_ids(mut_repo, &format!("{}::", commit2.id())), vec![ commit6.id().clone(), commit5.id().clone(), @@ -1914,7 +1863,7 @@ fn test_evaluate_expression_descendants() { // Can find descendants of children or children of descendants, which may be // optimized to single query assert_eq!( - resolve_commit_ids(mut_repo, &format!("({}+)::", commit1.id().hex())), + resolve_commit_ids(mut_repo, &format!("({}+)::", commit1.id())), vec![ commit6.id().clone(), commit5.id().clone(), @@ -1924,7 +1873,7 @@ fn test_evaluate_expression_descendants() { ] ); assert_eq!( - resolve_commit_ids(mut_repo, &format!("({}++)::", commit1.id().hex())), + resolve_commit_ids(mut_repo, &format!("({}++)::", commit1.id())), vec![ commit6.id().clone(), commit5.id().clone(), @@ -1934,7 +1883,7 @@ fn test_evaluate_expression_descendants() { assert_eq!( resolve_commit_ids( mut_repo, - &format!("(({}|{})::)+", commit4.id().hex(), commit2.id().hex()), + &format!("(({}|{})::)+", commit4.id(), commit2.id()), ), vec![ commit6.id().clone(), @@ -1945,7 +1894,7 @@ fn test_evaluate_expression_descendants() { assert_eq!( resolve_commit_ids( mut_repo, - &format!("(({}|{})+)::", commit4.id().hex(), commit2.id().hex()), + &format!("(({}|{})+)::", commit4.id(), commit2.id()), ), vec![ commit6.id().clone(), @@ -1956,15 +1905,15 @@ fn test_evaluate_expression_descendants() { // Can find next n descendants of a commit assert_eq!( - resolve_commit_ids(mut_repo, &format!("descendants({}, 0)", commit2.id().hex())), + resolve_commit_ids(mut_repo, &format!("descendants({}, 0)", commit2.id())), vec![] ); assert_eq!( - resolve_commit_ids(mut_repo, &format!("descendants({}, 1)", commit3.id().hex())), + resolve_commit_ids(mut_repo, &format!("descendants({}, 1)", commit3.id())), vec![commit3.id().clone()] ); assert_eq!( - resolve_commit_ids(mut_repo, &format!("descendants({}, 3)", commit3.id().hex())), + resolve_commit_ids(mut_repo, &format!("descendants({}, 3)", commit3.id())), vec![ commit6.id().clone(), commit5.id().clone(), @@ -2485,7 +2434,7 @@ fn test_evaluate_expression_merges() { ); // Searches only among candidates if specified assert_eq!( - resolve_commit_ids(mut_repo, &format!("::{} & merges()", commit5.id().hex())), + resolve_commit_ids(mut_repo, &format!("::{} & merges()", commit5.id())), vec![commit5.id().clone()] ); } @@ -2611,7 +2560,7 @@ fn test_evaluate_expression_author() { assert_eq!( resolve_commit_ids( mut_repo, - &format!("root().. & (author(name1) | {})", commit3.id().hex()) + &format!("root().. & (author(name1) | {})", commit3.id()) ), vec![commit3.id().clone(), commit1.id().clone()] ); @@ -2812,10 +2761,7 @@ fn test_evaluate_expression_mine() { ); // Filter by union of pure predicate and set assert_eq!( - resolve_commit_ids( - mut_repo, - &format!("root().. & (mine() | {})", commit1.id().hex()) - ), + resolve_commit_ids(mut_repo, &format!("root().. & (mine() | {})", commit1.id())), vec![ commit3.id().clone(), commit2.id().clone(), @@ -3048,7 +2994,7 @@ fn test_evaluate_expression_union() { assert_eq!( resolve_commit_ids( mut_repo, - &format!("::{} | ::{}", commit4.id().hex(), commit5.id().hex()) + &format!("::{} | ::{}", commit4.id(), commit5.id()) ), vec![ commit5.id().clone(), @@ -3066,9 +3012,9 @@ fn test_evaluate_expression_union() { mut_repo, &format!( "(::{} ~ ::{}) | ::{}", - commit4.id().hex(), - commit2.id().hex(), - commit5.id().hex() + commit4.id(), + commit2.id(), + commit5.id() ) ), vec![ @@ -3087,9 +3033,9 @@ fn test_evaluate_expression_union() { mut_repo, &format!( "(::{} ~ ::{}) | {}", - commit4.id().hex(), - commit2.id().hex(), - commit5.id().hex(), + commit4.id(), + commit2.id(), + commit5.id(), ) ), vec![ @@ -3114,7 +3060,7 @@ fn test_evaluate_expression_machine_generated_union() { // This query shouldn't trigger stack overflow. Here we use "x::y" in case // we had optimization path for trivial "commit_id|.." expression. - let revset_str = iter::repeat(format!("({}::{})", commit1.id().hex(), commit2.id().hex())) + let revset_str = iter::repeat(format!("({}::{})", commit1.id(), commit2.id())) .take(5000) .join("|"); assert_eq!( @@ -3143,7 +3089,7 @@ fn test_evaluate_expression_intersection() { assert_eq!( resolve_commit_ids( mut_repo, - &format!("::{} & ::{}", commit4.id().hex(), commit5.id().hex()) + &format!("::{} & ::{}", commit4.id(), commit5.id()) ), vec![ commit2.id().clone(), @@ -3154,10 +3100,7 @@ fn test_evaluate_expression_intersection() { // Intersection of disjoint sets assert_eq!( - resolve_commit_ids( - mut_repo, - &format!("{} & {}", commit4.id().hex(), commit2.id().hex()) - ), + resolve_commit_ids(mut_repo, &format!("{} & {}", commit4.id(), commit2.id())), vec![] ); } @@ -3180,7 +3123,7 @@ fn test_evaluate_expression_difference() { // Difference from all assert_eq!( - resolve_commit_ids(mut_repo, &format!("~::{}", commit5.id().hex())), + resolve_commit_ids(mut_repo, &format!("~::{}", commit5.id())), vec![commit4.id().clone(), commit3.id().clone()] ); @@ -3188,28 +3131,28 @@ fn test_evaluate_expression_difference() { assert_eq!( resolve_commit_ids( mut_repo, - &format!("::{} ~ ::{}", commit4.id().hex(), commit5.id().hex()) + &format!("::{} ~ ::{}", commit4.id(), commit5.id()) ), vec![commit4.id().clone(), commit3.id().clone()] ); assert_eq!( resolve_commit_ids( mut_repo, - &format!("::{} ~ ::{}", commit5.id().hex(), commit4.id().hex()) + &format!("::{} ~ ::{}", commit5.id(), commit4.id()) ), vec![commit5.id().clone()] ); assert_eq!( resolve_commit_ids( mut_repo, - &format!("~::{} & ::{}", commit4.id().hex(), commit5.id().hex()) + &format!("~::{} & ::{}", commit4.id(), commit5.id()) ), vec![commit5.id().clone()] ); assert_eq!( resolve_commit_ids( mut_repo, - &format!("::{} ~ ::{}", commit4.id().hex(), commit2.id().hex()) + &format!("::{} ~ ::{}", commit4.id(), commit2.id()) ), vec![commit4.id().clone(), commit3.id().clone()] ); @@ -3218,12 +3161,7 @@ fn test_evaluate_expression_difference() { assert_eq!( resolve_commit_ids( mut_repo, - &format!( - "::{} ~ {} ~ {}", - commit4.id().hex(), - commit2.id().hex(), - commit3.id().hex() - ) + &format!("::{} ~ {} ~ {}", commit4.id(), commit2.id(), commit3.id()) ), vec![ commit4.id().clone(), @@ -3238,10 +3176,10 @@ fn test_evaluate_expression_difference() { mut_repo, &format!( "(::{} ~ ::{}) ~ (::{} ~ ::{})", - commit4.id().hex(), - commit1.id().hex(), - commit3.id().hex(), - commit1.id().hex(), + commit4.id(), + commit1.id(), + commit3.id(), + commit1.id(), ) ), vec![commit4.id().clone()] @@ -3302,10 +3240,7 @@ fn test_evaluate_expression_filter_combinator() { assert_eq!( resolve_commit_ids( mut_repo, - &format!( - "{}.. & (description(1) | description(2))", - commit1.id().hex(), - ) + &format!("{}.. & (description(1) | description(2))", commit1.id()), ), vec![commit2.id().clone()], ); @@ -3413,10 +3348,7 @@ fn test_evaluate_expression_file() { assert_eq!( resolve_commit_ids_in_workspace( mut_repo, - &format!( - r#"{}:: & files("added_modified_clean")"#, - commit2.id().hex() - ), + &format!(r#"{}:: & files("added_modified_clean")"#, commit2.id()), &test_workspace.workspace, Some(test_workspace.workspace.workspace_root()), ), @@ -3425,7 +3357,7 @@ fn test_evaluate_expression_file() { // empty() revset, which is identical to ~file(".") assert_eq!( - resolve_commit_ids(mut_repo, &format!("{}:: & empty()", commit1.id().hex())), + resolve_commit_ids(mut_repo, &format!("{}:: & empty()", commit1.id())), vec![commit4.id().clone()] ); } diff --git a/lib/testutils/src/lib.rs b/lib/testutils/src/lib.rs index b6750e9c3..c9fe5f996 100644 --- a/lib/testutils/src/lib.rs +++ b/lib/testutils/src/lib.rs @@ -430,18 +430,13 @@ pub fn dump_tree(store: &Arc, tree_id: &MergedTreeId) -> String { Ok(Some(TreeValue::File { id, executable: _ })) => { let file_buf = read_file(store, &path, &id); let file_contents = String::from_utf8_lossy(&file_buf); - writeln!( - &mut buf, - " file {path:?} ({}): {file_contents:?}", - id.hex() - ) - .unwrap(); + writeln!(&mut buf, " file {path:?} ({id}): {file_contents:?}").unwrap(); } Ok(Some(TreeValue::Symlink(id))) => { - writeln!(&mut buf, " symlink {path:?} ({})", id.hex()).unwrap(); + writeln!(&mut buf, " symlink {path:?} ({id})").unwrap(); } Ok(Some(TreeValue::GitSubmodule(id))) => { - writeln!(&mut buf, " submodule {path:?} ({})", id.hex()).unwrap(); + writeln!(&mut buf, " submodule {path:?} ({id})").unwrap(); } entry => { unimplemented!("dumping tree entry {entry:?}");