Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 13, 2025

This PR implements the missing is_empty_tree() and is_empty_blob() methods for the borrowed gix_hash::oid type to match the functionality already available in the owned gix_hash::ObjectId type.

Problem

The ObjectId type already provides these convenience methods:

let empty_blob = ObjectId::empty_blob(Kind::Sha1);
assert!(empty_blob.is_empty_blob());
assert!(empty_blob.is_empty_tree() == false);

However, the borrowed oid type only had is_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 existing is_null() implementation:

  • is_empty_blob() - Returns true if the hash equals the empty blob hash
  • is_empty_tree() - Returns true if the hash equals the empty tree hash

The implementation uses the same SHA-1 byte constants as ObjectId and follows the established pattern of comparing against static helper methods.

Implementation Details

  • Added static helper methods empty_blob_sha1() and empty_tree_sha1() in the "Sha1 specific methods" impl block
  • Added public is_empty_blob() and is_empty_tree() methods in the "Access" impl block
  • Uses identical byte constants as ObjectId::empty_blob() and ObjectId::empty_tree()
  • Added comprehensive tests including consistency validation between ObjectId and oid method behavior

Now 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.

@Copilot Copilot AI assigned Copilot and Byron Sep 13, 2025
@Copilot Copilot AI changed the title [WIP] Add is_empty_tree() and is_empty_blob() methods to gix_hash::Oid as well. Add is_empty_tree() and is_empty_blob() methods to gix_hash::Oid Sep 13, 2025
@Copilot Copilot AI requested a review from Byron September 13, 2025 15:00
Copilot finished work on behalf of Byron September 13, 2025 15:00
@Byron Byron force-pushed the copilot/fix-ffb06a30-3f53-4f82-94ed-51935d63da63 branch from a8d7293 to 58e2d18 Compare September 13, 2025 16:59
@Byron Byron marked this pull request as ready for review September 13, 2025 16:59
@Byron Byron enabled auto-merge September 13, 2025 16:59
@Byron Byron merged commit b4812d9 into main Sep 13, 2025
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants