Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 14, 2025

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 objects
  • find_header() - No longer returns synthetic headers for empty blobs
  • try_find_object() - No longer returns synthetic empty blob objects
  • try_find_header() - No longer returns synthetic headers for empty blobs
  • has_object() - No longer treats empty blobs as always present

The empty tree special handling remains unchanged.

Test Updates

Updated test expectations in gix/tests/gix/repository/object.rs:

  • Renamed empty_blob_can_always_be_found to empty_blob_can_be_found_if_it_exists to reflect new behavior
  • Updated empty_objects_are_always_present_but_not_in_plumbing to expect errors/None when empty blobs don't exist
  • Added test to verify the empty_blob() method still works correctly

Behavior Change

Before:

let repo = empty_repo();
let empty_blob_id = ObjectId::empty_blob(repo.object_hash());
assert!(repo.has_object(empty_blob_id)); // Always true
let obj = repo.find_object(empty_blob_id)?; // Always succeeds with synthetic object

After:

let repo = empty_repo();
let empty_blob_id = ObjectId::empty_blob(repo.object_hash());
assert!(!repo.has_object(empty_blob_id)); // False if not in repository
repo.find_object(empty_blob_id).unwrap_err(); // Errors if not found

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.

@Copilot Copilot AI assigned Copilot and Byron Sep 14, 2025
@Copilot Copilot AI changed the title [WIP] Remove handling the empty blob hash specifically in gix - if it doesn't exist it's an error. Leave the existing tests, but adjust expectations. Remove special handling of empty blob hash in gix - treat as error if not found Sep 14, 2025
@Copilot Copilot AI requested a review from Byron September 14, 2025 03:47
Copilot finished work on behalf of Byron September 14, 2025 03:47
Copilot AI and others added 2 commits September 14, 2025 08:20
This feature was recently introduced, but was never released.

Co-authored-by: Byron <63622+Byron@users.noreply.github.com>
@Byron Byron force-pushed the copilot/fix-54bce74a-dc5e-4361-b53b-326c16b34046 branch from 264ee04 to b9c7a7e Compare September 14, 2025 06:30
@Byron Byron marked this pull request as ready for review September 14, 2025 06:30
@Byron Byron enabled auto-merge September 14, 2025 06:30
@Byron Byron merged commit e60e253 into main Sep 14, 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