From 7fca001b13d22a0aa7e2196018323b3edca7586a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 13 Sep 2025 18:46:01 +0200 Subject: [PATCH 1/2] feat: Add `Kind::empty_blob()`` and `Kind::empty_tree()`` methods. --- gix-hash/src/kind.rs | 12 ++++++++++++ gix-hash/tests/hash/kind.rs | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/gix-hash/src/kind.rs b/gix-hash/src/kind.rs index 5c7a0316b8d..a06f4df119a 100644 --- a/gix-hash/src/kind.rs +++ b/gix-hash/src/kind.rs @@ -113,4 +113,16 @@ impl Kind { Kind::Sha1 => ObjectId::null_sha1(), } } + + /// Create an owned empty-blob id of our hash kind. + #[inline] + pub const fn empty_blob(&self) -> ObjectId { + ObjectId::empty_blob(*self) + } + + /// Create an owned empty-tree id of our hash kind. + #[inline] + pub const fn empty_tree(&self) -> ObjectId { + ObjectId::empty_tree(*self) + } } diff --git a/gix-hash/tests/hash/kind.rs b/gix-hash/tests/hash/kind.rs index 300a679fd2c..55182ea8122 100644 --- a/gix-hash/tests/hash/kind.rs +++ b/gix-hash/tests/hash/kind.rs @@ -14,3 +14,19 @@ mod from_hex_len { assert_eq!(Kind::from_hex_len(65), None); } } + +mod empty_objects { + use gix_hash::{Kind, ObjectId}; + + #[test] + fn empty_blob() { + let kind = Kind::Sha1; + assert_eq!(kind.empty_blob(), ObjectId::empty_blob(kind)); + } + + #[test] + fn empty_tree() { + let kind = Kind::Sha1; + assert_eq!(kind.empty_tree(), ObjectId::empty_tree(kind)); + } +} From 41c40adf3d1a8505dd53dc49a6940c834e71e169 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 13 Sep 2025 18:49:03 +0200 Subject: [PATCH 2/2] refactor --- gix-hash/src/kind.rs | 4 ++-- gix-hash/tests/hash/kind.rs | 24 +++++++++++------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/gix-hash/src/kind.rs b/gix-hash/src/kind.rs index a06f4df119a..de787b417fd 100644 --- a/gix-hash/src/kind.rs +++ b/gix-hash/src/kind.rs @@ -114,13 +114,13 @@ impl Kind { } } - /// Create an owned empty-blob id of our hash kind. + /// The hash of an empty blob. #[inline] pub const fn empty_blob(&self) -> ObjectId { ObjectId::empty_blob(*self) } - /// Create an owned empty-tree id of our hash kind. + /// The hash of an empty tree. #[inline] pub const fn empty_tree(&self) -> ObjectId { ObjectId::empty_tree(*self) diff --git a/gix-hash/tests/hash/kind.rs b/gix-hash/tests/hash/kind.rs index 55182ea8122..ec5bf3f1737 100644 --- a/gix-hash/tests/hash/kind.rs +++ b/gix-hash/tests/hash/kind.rs @@ -1,3 +1,5 @@ +use gix_hash::{Kind, ObjectId}; + mod from_hex_len { use gix_hash::Kind; @@ -15,18 +17,14 @@ mod from_hex_len { } } -mod empty_objects { - use gix_hash::{Kind, ObjectId}; - - #[test] - fn empty_blob() { - let kind = Kind::Sha1; - assert_eq!(kind.empty_blob(), ObjectId::empty_blob(kind)); - } +#[test] +fn empty_blob() { + let sha1 = Kind::Sha1; + assert_eq!(sha1.empty_blob(), ObjectId::empty_blob(sha1)); +} - #[test] - fn empty_tree() { - let kind = Kind::Sha1; - assert_eq!(kind.empty_tree(), ObjectId::empty_tree(kind)); - } +#[test] +fn empty_tree() { + let sha1 = Kind::Sha1; + assert_eq!(sha1.empty_tree(), ObjectId::empty_tree(sha1)); }