Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 13, 2025

This PR adds two new convenience methods to the Kind enum in the gix-hash crate:

  • Kind::empty_blob(&self) -> ObjectId
  • Kind::empty_tree(&self) -> ObjectId

These methods provide a more ergonomic way to get empty blob and tree object IDs for a specific hash kind, complementing the existing ObjectId::empty_blob(Kind) and ObjectId::empty_tree(Kind) static methods.

Usage

use gix_hash::Kind;

let kind = Kind::Sha1;

// Before: had to use ObjectId static methods
let empty_blob = ObjectId::empty_blob(kind);
let empty_tree = ObjectId::empty_tree(kind);

// Now: can use Kind instance methods directly
let empty_blob = kind.empty_blob();
let empty_tree = kind.empty_tree();

Implementation Details

  • Both methods are const fn to match the existing ObjectId implementations
  • They delegate to the existing ObjectId::empty_blob(kind) and ObjectId::empty_tree(kind) methods
  • Follows the same pattern as the existing Kind::null() method
  • Added comprehensive tests to ensure the methods return identical results to their ObjectId counterparts

This change maintains the existing gix crate's Repository::empty_blob() and Repository::empty_tree() methods while providing the requested functionality at the Kind level for consistency with the existing API design.


✨ 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] In the gix crate, there is Repository::empty_blob() and Repository::empty_tree(). In gix-hash, add Kind::empty_blob() and Kind::empty_tree() as well. Add Kind::empty_blob() and Kind::empty_tree() methods to gix-hash Sep 13, 2025
@Copilot Copilot AI requested a review from Byron September 13, 2025 14:54
Copilot finished work on behalf of Byron September 13, 2025 14:54
@Byron Byron force-pushed the copilot/fix-ceb7b1a4-93f5-4da1-a4f2-4290c8f594eb branch from 0a2e5be to 41c40ad Compare September 13, 2025 16:51
@Byron Byron marked this pull request as ready for review September 13, 2025 16:51
@Byron Byron enabled auto-merge September 13, 2025 16:51
@Byron Byron merged commit 772c434 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