Skip to content

test sha256 git2#2

Closed
weihanglo wants to merge 13 commits into
mainfrom
test-sha256-git2
Closed

test sha256 git2#2
weihanglo wants to merge 13 commits into
mainfrom
test-sha256-git2

Conversation

@weihanglo
Copy link
Copy Markdown
Owner

No description provided.

weihanglo added 13 commits May 14, 2026 18:44
This is a preparation of SHA256 support.

* Added `Oid::object_format()`
* Added `Oid::raw_bytes()`
* Changed `Oid::from_bytes()` to use `GIT_OID_SHA1_SIZE`
* Added `Repository::object_format()`
* Added `Remote::object_format()`
* Added `RepositoryInitOptions::object_format()`
Add `*_ext` method variants that accept an `ObjectFormat` param.
The short-hand methods now delegate to `_ext` variants with Sha1.

* Added `Oid::from_str_ext`
* Added `Oid::hash_object_ext`
* Added `Oid::hash_file_ext`
* Added `Diff::from_buffer_ext`
* Added `Index::new_ext`
* Added `Index::open_ext`
* Added `Indexer::new_ext`
* Added `Odb::new_ext`
This makes these call sites automatically handle
the correct object format once SHA256 support is wired up.
Declare the `unstable-sha256` Cargo feature,
reflecting upstream libgit2's `GIT_EXPERIMENTAL_SHA256`.
This is an ABI-breaking experimental feature.

Implement the SHA256 support gated behind this feature:

Things gated:

* `ObjectFormat::Sha256` and non_exhaustive when `unstable-sha256` is off
* all FFI call sites for the overloaded libgit2 function signatures
  * git_oid_fromstrn
  * git_oid_fromraw,
  * git_odb_hash
  * git_odb_hashfile
  * git_diff_from_buffer,
  * git_index_new
  * git_index_open
  * git_indexer_new
  * git_odb_new
* `Repository::object_format` is format-aware
* `Remote::object_format` is format-aware
* `Oid::{as_bytes,object_format,from_bytes}` are format-aware
`Oid::zero().object_format()` panics with `unstable-sha256`
because the raw `kind` field was left as zero.

The zeroed struct is generally use for output param.
Not really meaning to switch a `zero_ext` variant.

Replace it with const values for both kinds.
Construct `git_oid` with a struct literal instead of `mem::zeroed`.

Under `unstable-sha256`,
default `kind` to `GIT_OID_SHA1` so the value is a valid `git_oid_t`
even before libgit2 overwrites it as an output buffer.
@weihanglo weihanglo closed this May 15, 2026
@weihanglo weihanglo deleted the test-sha256-git2 branch May 16, 2026 21:32
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.

1 participant