Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 13, 2025

This PR extends the existing empty object handling in gix::Repository::has_object() to include empty blob IDs, making it consistent with the current empty tree behavior.

Problem

Previously, has_object() only treated empty tree IDs as always present, but empty blob IDs would be looked up in the object database even though they represent a conceptual object that should always exist (similar to empty trees).

let repo = gix::Repository::open(".")?;
let empty_tree = gix::ObjectId::empty_tree(repo.object_hash());
let empty_blob = gix::ObjectId::empty_blob(repo.object_hash());

assert!(repo.has_object(empty_tree));  // ✅ Already worked
assert!(repo.has_object(empty_blob));  // ❌ Would fail if not physically present

Solution

Extended the special case handling in has_object() and related methods to include empty blob IDs:

  • Modified has_object(): Now checks is_empty_blob() alongside is_empty_tree()
  • Updated find methods for consistency: find_object(), try_find_object(), find_header(), and try_find_header() all handle empty blobs the same way they handle empty trees
  • Returns appropriate object metadata: Empty blobs are treated as loose objects with Kind::Blob and size 0

Changes

The implementation follows the exact same pattern as empty tree handling:

pub fn has_object(&self, id: impl AsRef<gix_hash::oid>) -> bool {
    let id = id.as_ref();
    if id.to_owned().is_empty_tree() || id.to_owned().is_empty_blob() {
        true
    } else {
        self.objects.exists(id)
    }
}

Testing

Added comprehensive tests mirroring the existing empty tree test structure:

  • empty_blob_can_always_be_found: Verifies all find operations work correctly
  • empty_blob_is_always_considered_present: Tests core has_object() functionality
  • empty_blob_edge_cases: Validates all related methods handle empty blobs properly

All existing tests continue to pass, ensuring backward compatibility.

Impact

This change makes empty blob handling consistent with empty tree handling, improving the API's predictability. Empty blobs (SHA1: e69de29bb2d1d6434b8b29ae775ad8c2e48c5391) are now guaranteed to be considered present regardless of their physical storage state.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI assigned Copilot and Byron Sep 13, 2025
@Copilot Copilot AI changed the title [WIP] gix::Repository::has_object() should consider empty blob ids to be always present as well. Make gix::Repository::has_object() consider empty blob ids to be always present Sep 13, 2025
Copilot finished work on behalf of Byron September 13, 2025 15:07
@Copilot Copilot AI requested a review from Byron September 13, 2025 15:07
Copilot AI and others added 2 commits September 13, 2025 19:02
Co-authored-by: Byron <63622+Byron@users.noreply.github.com>
@Byron Byron force-pushed the copilot/fix-3952f55e-8faf-4737-886f-09e74cab4ca8 branch from 55a1fcb to 689d839 Compare September 13, 2025 17:14
@Byron Byron marked this pull request as ready for review September 13, 2025 17:15
@Byron Byron enabled auto-merge September 13, 2025 17:15
@Byron Byron merged commit 1a4c84d 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