Make gix::Repository::has_object()
consider empty blob ids to be always present
#2167
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 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).Solution
Extended the special case handling in
has_object()
and related methods to include empty blob IDs:has_object()
: Now checksis_empty_blob()
alongsideis_empty_tree()
find_object()
,try_find_object()
,find_header()
, andtry_find_header()
all handle empty blobs the same way they handle empty treesKind::Blob
and size 0Changes
The implementation follows the exact same pattern as empty tree handling:
Testing
Added comprehensive tests mirroring the existing empty tree test structure:
empty_blob_can_always_be_found
: Verifies all find operations work correctlyempty_blob_is_always_considered_present
: Tests corehas_object()
functionalityempty_blob_edge_cases
: Validates all related methods handle empty blobs properlyAll 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.