-
Notifications
You must be signed in to change notification settings - Fork 433
feat(sys): experimental SHA256 OID support #1201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ehuss
left a comment
There was a problem hiding this 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-sys/build.rs
Outdated
| libgit2_vendored,\ | ||
| )" | ||
| ); | ||
| println!("cargo:rustc-check-cfg=cfg(libgit2_experimental_sha256)"); |
There was a problem hiding this comment.
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.
|
Thanks for the review!
Yes. Due to my limited time on this, that will be the most straightforward option. I plan to only add API that Cargo needs.
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. |
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
What this is for
Integrate upstream libgit2 experimental SHA256 support in
libgit2-sys, includingunstable-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-syssystem lib probing also support discoveringlibgit2-experimental.soat best effort. Since-experimentallib is ABI-incompatible with a normal build, if you enableunstable-sha256, it won't probe ordinarylibgit2.so.systestto 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
GIT_OID_SHA1_SIZEGIT_OID_SHA1_HEXSIZEGIT_OID_RAWSZ(whenusntable-sha256enabled)GIT_OID_HEXSZ(whenusntable-sha256enabled)GIT_OID_SHA256_SIZEGIT_OID_SHA256_HEXSIZEGIT_OID_MAX_SIZE(size varies onunstable-sha256feature)GIT_OID_MAX_HEXSIZE(size varies onunstable-sha256feature)GIT_INDEX_OPTIONS_INITGIT_INDEX_OPTIONS_VERSIONGIT_REPOSITORY_NEW_OPTIONS_INITGIT_REPOSITORY_NEW_OPTIONS_VERSIONGIT_ODB_OPTIONS_VERSIONGIT_ODB_BACKEND_PACK_OPTIONS_VERSIONGIT_ODB_BACKEND_LOOSE_OPTIONS_VERSIONGIT_DIFF_PARSE_OPTIONS_VERSIONChanges in structs
git_oid.typefieldgit_oid.idmax size is nowGIT_OID_MAX_SIZEgit_repository_init_options.oid_typefieldgit_index_optionsgit_repository_new_optionsgit_odb_optionsgit_odb_backend_pack_optionsgit_odb_backend_loose_optionsgit_diff_parse_optionsChanges in
GIT_EXTERNfunctions (need to expose)git_diff_from_bufferSHA256 supportgit_index_newSHA256 supportgit_index_openSHA256 supportgit_index_options_initSHA256 supportgit_indexer_newSHA256 supportgit_object_rawcontent_is_validfor both SHA1 and SHA256git_odb_backend_looseSHA256 supportgit_odb_backend_one_packSHA256 supportgit_odb_backend_packSHA256 supportgit_odb_hashSHA256 supportgit_odb_hashfileSHA256 supportgit_odb_newSHA256 supportgit_odb_openfor both SHA1 and SHA256git_repository_newint GIT_CALLBACK(oid_type)(git_oid_t *object_type, git_transport *transport)git_commit_graph_*not blocking the SHA256 experimentgit_midx_writer_*not blocking the SHA256 experimentChanges in
GIT_INLINEfunctions (no need to expose)git_oid_algorithmgit_oid_cleargit_oid_hexsizegit_oid_sizegit_oid_typegit_oid_type_fromstrgit_oid_type_fromstrngit_oid_type_is_validgit_oid_type_namegit_oid__cmpgit_oid__cpy_prefix