diff --git a/Cargo.lock b/Cargo.lock
index a0072b2f7e..40326df0a9 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1625,12 +1625,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc"
-[[package]]
-name = "hex"
-version = "0.4.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
-
[[package]]
name = "home"
version = "0.5.9"
@@ -1833,6 +1827,7 @@ dependencies = [
"dirs",
"dunce",
"esl01-renderdag",
+ "faster-hex",
"futures 0.3.30",
"git2",
"gix",
@@ -1891,7 +1886,6 @@ dependencies = [
"gix",
"gix-filter",
"glob",
- "hex",
"ignore",
"indexmap",
"indoc",
@@ -3096,9 +3090,9 @@ version = "0.21.0"
dependencies = [
"async-trait",
"config",
+ "faster-hex",
"futures 0.3.30",
"git2",
- "hex",
"itertools 0.13.0",
"jj-lib",
"pollster",
diff --git a/Cargo.toml b/Cargo.toml
index 9fbebeb5f8..36080bfe63 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -66,7 +66,7 @@ gix = { version = "0.66.0", default-features = false, features = [
] }
gix-filter = "0.13.0"
glob = "0.3.1"
-hex = "0.4.3"
+faster-hex = { version = "0.9.0", default-features = false, features = ["std"]}
ignore = "0.4.23"
indexmap = "2.5.0"
indoc = "2.0.4"
diff --git a/cli/Cargo.toml b/cli/Cargo.toml
index ef261d1782..ecafc4e0bb 100644
--- a/cli/Cargo.toml
+++ b/cli/Cargo.toml
@@ -64,6 +64,7 @@ esl01-renderdag = { workspace = true }
futures = { workspace = true }
git2 = { workspace = true }
gix = { workspace = true }
+faster-hex = { workspace = true }
indexmap = { workspace = true }
indoc = { workspace = true }
itertools = { workspace = true }
diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs
index c49af6b773..7a8056907b 100644
--- a/cli/src/cli_util.rs
+++ b/cli/src/cli_util.rs
@@ -64,7 +64,6 @@ use jj_lib::git;
use jj_lib::git_backend::GitBackend;
use jj_lib::gitignore::GitIgnoreError;
use jj_lib::gitignore::GitIgnoreFile;
-use jj_lib::hex_util::to_reverse_hex;
use jj_lib::id_prefix::IdPrefixContext;
use jj_lib::matchers::Matcher;
use jj_lib::merge::MergedTreeValue;
@@ -2632,17 +2631,21 @@ pub fn edit_temp_file(
}
pub fn short_commit_hash(commit_id: &CommitId) -> String {
- commit_id.hex()[0..12].to_string()
+ let mut hash = commit_id.hex();
+ hash.truncate(12);
+ hash
}
pub fn short_change_hash(change_id: &ChangeId) -> String {
- // TODO: We could avoid the unwrap() and make this more efficient by converting
- // straight from binary.
- to_reverse_hex(&change_id.hex()[0..12]).unwrap()
+ let mut hash = change_id.reverse_hex();
+ hash.truncate(12);
+ hash
}
pub fn short_operation_hash(operation_id: &OperationId) -> String {
- operation_id.hex()[0..12].to_string()
+ let mut hash = operation_id.hex();
+ hash.truncate(12);
+ hash
}
/// Wrapper around a `DiffEditor` to conditionally start interactive session.
diff --git a/cli/src/commands/debug/tree.rs b/cli/src/commands/debug/tree.rs
index 7c40d33b57..38e2647e07 100644
--- a/cli/src/commands/debug/tree.rs
+++ b/cli/src/commands/debug/tree.rs
@@ -47,7 +47,7 @@ pub fn cmd_debug_tree(
let workspace_command = command.workspace_helper(ui)?;
let tree = if let Some(tree_id_hex) = &args.id {
let tree_id =
- TreeId::try_from_hex(tree_id_hex).map_err(|_| user_error("Invalid tree id"))?;
+ TreeId::try_from_hex(tree_id_hex).ok_or_else(|| user_error("Invalid tree id"))?;
let dir = if let Some(dir_str) = &args.dir {
workspace_command.parse_file_path(dir_str)?
} else {
diff --git a/cli/src/commit_templater.rs b/cli/src/commit_templater.rs
index d52dbcd0ce..95c531df71 100644
--- a/cli/src/commit_templater.rs
+++ b/cli/src/commit_templater.rs
@@ -31,7 +31,6 @@ use jj_lib::fileset;
use jj_lib::fileset::FilesetDiagnostics;
use jj_lib::fileset::FilesetExpression;
use jj_lib::git;
-use jj_lib::hex_util::to_reverse_hex;
use jj_lib::id_prefix::IdPrefixContext;
use jj_lib::matchers::Matcher;
use jj_lib::merged_tree::MergedTree;
@@ -1248,11 +1247,7 @@ impl CommitOrChangeId {
pub fn hex(&self) -> String {
match self {
CommitOrChangeId::Commit(id) => id.hex(),
- CommitOrChangeId::Change(id) => {
- // TODO: We can avoid the unwrap() and make this more efficient by converting
- // straight from bytes.
- to_reverse_hex(&id.hex()).unwrap()
- }
+ CommitOrChangeId::Change(id) => id.reverse_hex(),
}
}
diff --git a/lib/Cargo.toml b/lib/Cargo.toml
index e45e45f881..4834c40e29 100644
--- a/lib/Cargo.toml
+++ b/lib/Cargo.toml
@@ -48,7 +48,6 @@ git2 = { workspace = true, optional = true }
gix = { workspace = true, optional = true }
gix-filter = { workspace = true, optional = true }
glob = { workspace = true }
-hex = { workspace = true }
ignore = { workspace = true }
indexmap = { workspace = true }
itertools = { workspace = true }
diff --git a/lib/src/backend.rs b/lib/src/backend.rs
index 32b04ae26c..a5786e5d52 100644
--- a/lib/src/backend.rs
+++ b/lib/src/backend.rs
@@ -25,6 +25,7 @@ use futures::stream::BoxStream;
use thiserror::Error;
use crate::content_hash::ContentHash;
+use crate::hex_util;
use crate::index::Index;
use crate::merge::Merge;
use crate::object_id::id_type;
@@ -50,6 +51,12 @@ id_type!(pub FileId);
id_type!(pub SymlinkId);
id_type!(pub ConflictId);
+impl ChangeId {
+ pub fn reverse_hex(&self) -> String {
+ hex_util::encode_hex_string_reverse(&self.0)
+ }
+}
+
#[derive(ContentHash, Debug, PartialEq, Eq, Clone, Copy, PartialOrd, Ord)]
pub struct MillisSinceEpoch(pub i64);
diff --git a/lib/src/content_hash.rs b/lib/src/content_hash.rs
index e3918589af..bbe9235672 100644
--- a/lib/src/content_hash.rs
+++ b/lib/src/content_hash.rs
@@ -151,6 +151,7 @@ mod tests {
use std::collections::HashMap;
use super::*;
+ use crate::hex_util;
#[test]
fn test_string_sanity() {
@@ -215,7 +216,7 @@ mod tests {
x: Vec