Skip to content

Conversation

@weihanglo
Copy link
Member

@weihanglo weihanglo commented Dec 22, 2025

What this is for

Integrate upstream libgit2 experimental SHA256 support in libgit2-sys, including

  • A new unstable Cargo feature unstable-sha256, gating all new ABI/API changes. We don't offer any SemVer or stability for this feature, as it is subject to change in upstream.
  • libgit2-sys system lib probing also support discovering libgit2-experimental.so at best effort. Since -experimental lib is ABI-incompatible with a normal build, if you enable unstable-sha256, it won't probe ordinary libgit2.so.
  • Extend systest to check SHA256 bindings.

Note: there is no git2-rs high level API support in this PR

Part of #1090

Full list of API changes

Changes in constants

  • NEW GIT_OID_SHA1_SIZE
  • NEW GIT_OID_SHA1_HEXSIZE
  • DEPRECATED GIT_OID_RAWSZ (when usntable-sha256 enabled)
  • DEPRECATED GIT_OID_HEXSZ (when usntable-sha256 enabled)
  • NEW GIT_OID_SHA256_SIZE
  • NEW GIT_OID_SHA256_HEXSIZE
  • NEW GIT_OID_MAX_SIZE (size varies on unstable-sha256 feature)
  • NEW GIT_OID_MAX_HEXSIZE (size varies on unstable-sha256 feature)
  • NEW GIT_INDEX_OPTIONS_INIT
  • NEW GIT_INDEX_OPTIONS_VERSION
  • NEW GIT_REPOSITORY_NEW_OPTIONS_INIT
  • NEW GIT_REPOSITORY_NEW_OPTIONS_VERSION
  • NEW GIT_ODB_OPTIONS_VERSION
  • NEW GIT_ODB_BACKEND_PACK_OPTIONS_VERSION
  • NEW GIT_ODB_BACKEND_LOOSE_OPTIONS_VERSION
  • NEW GIT_DIFF_PARSE_OPTIONS_VERSION

Changes in structs

  • NEW git_oid.type field
  • CHANGED git_oid.id max size is now GIT_OID_MAX_SIZE
  • NEW git_repository_init_options.oid_type field
  • NEW git_index_options
  • NEW git_repository_new_options
  • NEW git_odb_options
  • NEW git_odb_backend_pack_options
  • NEW git_odb_backend_loose_options
  • NEW git_diff_parse_options

Changes in GIT_EXTERN functions (need to expose)

  • CHANGED git_diff_from_buffer SHA256 support
  • CHANGED git_index_new SHA256 support
  • CHANGED git_index_open SHA256 support
  • NEW git_index_options_init SHA256 support
  • CHANGED git_indexer_new SHA256 support
  • NEW git_object_rawcontent_is_valid for both SHA1 and SHA256
  • CHANGED git_odb_backend_loose SHA256 support
  • CHANGED git_odb_backend_one_pack SHA256 support
  • CHANGED git_odb_backend_pack SHA256 support
  • CHANGED git_odb_hash SHA256 support
  • CHANGED git_odb_hashfile SHA256 support
  • CHANGED git_odb_new SHA256 support
  • NEW git_odb_open for both SHA1 and SHA256
  • CHANGED git_repository_new
  • NEW int GIT_CALLBACK(oid_type)(git_oid_t *object_type, git_transport *transport)
  • SKIPPED git_commit_graph_* not blocking the SHA256 experiment
  • SKIPPED git_midx_writer_* not blocking the SHA256 experiment

Changes in GIT_INLINE functions (no need to expose)

  • git_oid_algorithm
  • git_oid_clear
  • git_oid_hexsize
  • git_oid_size
  • git_oid_type
  • git_oid_type_fromstr
  • git_oid_type_fromstrn
  • git_oid_type_is_valid
  • git_oid_type_name
  • git_oid__cmp
  • git_oid__cpy_prefix

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.

Nice!

I have not reviewed this super closely, but generally looks good.

I had some questions:

  • What kind of high-level API support might we want in the future? Would we add something to RepositoryInitOptions? Are there other areas you think we will need extensions?
  • Is there some way to add a test that ensures it can open and read a repository that uses SHA256? Or does that require adding the high-level API?

Feel free to merge with or without the nit below.

libgit2_vendored,\
)"
);
println!("cargo:rustc-check-cfg=cfg(libgit2_experimental_sha256)");
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this just be added to the print just above it?
It takes a comma-separated list, right?

I think that's the reason why it is formatted the way it is. The intent was to make it easy to add additional cfg values (one per line).

This reflects upstream libgit2's GIT_EXPERIMENTAL_SHA256.

This is an ABI-breaking change.
Future releases with this feature may introduce breakages without notice
Use at your own risk.

Library authors:
DO NOT enable this feature by default in your dependencies.
Due to Cargo's additive features,
downstream users cannot deactivate it once enabled.
@weihanglo
Copy link
Member Author

Thanks for the review!

  • What kind of high-level API support might we want in the future? Would we add something to RepositoryInitOptions? Are there other areas you think we will need extensions?

Yes. Due to my limited time on this, that will be the most straightforward option. I plan to only add API that Cargo needs.

  • Is there some way to add a test that ensures it can open and read a repository that uses SHA256? Or does that require adding the high-level API?

Slightly lean toward not adding test at sys crate level. If the binding is broken, it should be upstream's failure, not us. We definitely need to test sha256 support in git2-rs high level API.

@weihanglo weihanglo enabled auto-merge January 1, 2026 23:43
@weihanglo weihanglo added this pull request to the merge queue Jan 1, 2026
Merged via the queue into rust-lang:master with commit e9690cf Jan 1, 2026
7 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Waiting on review label Jan 1, 2026
@weihanglo weihanglo deleted the sha256 branch January 2, 2026 02:37
weihanglo added a commit to weihanglo/git2-rs that referenced this pull request Jan 3, 2026
This adds an `unstable-sha256` Cargo feature,
as a follow-up of rust-lang#1201

Also adds some smoke tests for affected operations/types.

## Insta-stable

* **NEW** `ObjectFormat` enum with variants `Sha1`
* **NEW** `Repository::object_format()` to query hash algorithm
* **NEW** `Index::with_object_format` to create with different format

## Behind `unstable-sha256

* **NEW** `ObjectFormat` enum with variants `Sha1` and `Sha256`
* **NEW** `RepositoryInitOptions::object_format()` method to set hash algo
* **CHANGED** `Diff::from_buffer` to accept a extra object format argument
* **CHANGED** `Index::open` to accept a extra object format argument
* **CHANGED** `Indexer::new` to accept a extra object format argument
* **CHANGED** `Oid::from_str` to accept a extra object format argument
* **CHANGED** `Oid::hash_{object,file}` to accept a extra object format argument
* **REMOVED** `Index::new` to avoid misuse.
* **REMOVED** `impl std::FromStr for Oid` to avoid misuse
@weihanglo
Copy link
Member Author

#1202 is up, cc @ehuss

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new bindings Missing bindings for existing libgit2 functions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants