Remove special handling of empty blob hash in gix - treat as error if not found #2169
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 removes the special handling of empty blob hashes in
gix
, making them behave like regular objects that must actually exist in the repository to be found.Background
Previously,
gix
treated the empty blob hash specially across several repository methods, always returning synthetic empty blob objects even when the blob didn't physically exist in the object database. This behavior differed from how other objects are handled and could mask issues where code expected an empty blob to exist but it actually didn't.Changes Made
Repository Object Methods
Updated the following methods in
gix/src/repository/object.rs
to remove empty blob special cases:find_object()
- No longer returns synthetic empty blob objectsfind_header()
- No longer returns synthetic headers for empty blobstry_find_object()
- No longer returns synthetic empty blob objectstry_find_header()
- No longer returns synthetic headers for empty blobshas_object()
- No longer treats empty blobs as always presentThe empty tree special handling remains unchanged.
Test Updates
Updated test expectations in
gix/tests/gix/repository/object.rs
:empty_blob_can_always_be_found
toempty_blob_can_be_found_if_it_exists
to reflect new behaviorempty_objects_are_always_present_but_not_in_plumbing
to expect errors/None when empty blobs don't existempty_blob()
method still works correctlyBehavior Change
Before:
After:
This change makes empty blob handling consistent with other object types and ensures that operations only succeed when the object actually exists in the repository.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.