Skip to content

Conversation

@weihanglo
Copy link
Member

@weihanglo weihanglo commented Jan 11, 2026

  • Refactor zero Oid initialization in preparation for SHA256 support (libgit2 add a new type field to git_oid struct)
  • Reflect that upstream git_oid_iszero is deprecated. Use git_oid_is_zero instead.

(Spun off from #1202)

`git_oid_iszero` has been deprecated.
Raw git_oid binding has an extra field for object format kind.
The old all-zeroed struct is now an valid oid when the feature
`unstable-sha256` is enabled.

This adds an warning to the `Oid::zero` function that it should only be
used an output parameter when talking to C API. If you need valid zeroed
input parameter, use libgit2 constants `GIT_OID_SHA*_ZERO` instead.
@rustbot rustbot added the S-waiting-on-review Status: Waiting on review label Jan 11, 2026
Copy link
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I have some doubts if it makes sense to allow kind to be 0 in all situations, since that seems to be an invalid kind. But I don't immediately see any concerns.

@ehuss ehuss added this pull request to the merge queue Jan 11, 2026
Merged via the queue into rust-lang:master with commit d5eb7bb Jan 11, 2026
7 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Waiting on review label Jan 11, 2026
@weihanglo weihanglo deleted the zero-oid branch January 11, 2026 19:29
@weihanglo
Copy link
Member Author

Thanks!

I have some doubts if it makes sense to allow kind to be 0 in all situations, since that seems to be an invalid kind. But I don't immediately see any concerns.

Good call out!

For output param specifically, kind being 0 should be fine. libgit2 seems to always set out->type based on the type parameter passed to the function or the surrounding context.

For input param, user should not use Oid::zero. It guess somehow we should deprecate it in high level API during sha256 stabilization. Even with zero-initialized oid, libgit2 tends to call git_oid_is_zero and git_oid_is_type_valid to validate input param. I didn't do a full thorough check but seems likely fine.

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.

3 participants