Add is_empty_tree()
and is_empty_blob()
methods to gix_hash::Oid
#2166
+50
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements the missing
is_empty_tree()
andis_empty_blob()
methods for the borrowedgix_hash::oid
type to match the functionality already available in the ownedgix_hash::ObjectId
type.Problem
The
ObjectId
type already provides these convenience methods:However, the borrowed
oid
type only hadis_null()
but was missing the equivalent empty blob and tree detection methods, creating an inconsistency in the API.Solution
Added the missing methods to the
oid
type following the same patterns as the existingis_null()
implementation:is_empty_blob()
- Returnstrue
if the hash equals the empty blob hashis_empty_tree()
- Returnstrue
if the hash equals the empty tree hashThe implementation uses the same SHA-1 byte constants as
ObjectId
and follows the established pattern of comparing against static helper methods.Implementation Details
empty_blob_sha1()
andempty_tree_sha1()
in the "Sha1 specific methods" impl blockis_empty_blob()
andis_empty_tree()
methods in the "Access" impl blockObjectId::empty_blob()
andObjectId::empty_tree()
ObjectId
andoid
method behaviorNow both the owned and borrowed hash types provide the same convenience methods for detecting empty Git objects.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.