rust-lang / git2-rs

libgit2 bindings for Rust
https://docs.rs/git2
Apache License 2.0
1.72k stars 391 forks source link

Provide bindings to git_libgit2_opts #605

Open joshtriplett opened 4 years ago

joshtriplett commented 4 years ago

I'd like to be able to call git_libgit2_opts using git2-rs.

By default, when reading in objects, libgit2 computes their sha1 hash and confirms that it matches the expected hash. That's a reasonable default, but it costs a lot of performance. Calling git_libgit2_opts(GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, 0) can substantially improve the performance of reading objects.

git_libgit2_opts is a varargs function, and the arguments depend on the option. Thus, I'd suggest type-safe bindings for individual options.

taralx commented 4 years ago

I was just looking for exactly the same thing... Consider this my 👍 .

extrawurst commented 4 years ago

This will not be possible on stable rust until https://github.com/rust-lang/rust/issues/44930 is stabilised, right?

taralx commented 4 years ago

At least for the existing options, we could write C wrappers that provide non-variadic versions?

taralx commented 4 years ago

Also GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION is definitely the big one, so perhaps just supporting that for now? Maybe I'll put together a PR real quick.

joshtriplett commented 4 years ago

@extrawurst That feature is for defining C-compatible variadic functions in Rust. Stable Rust supports calling C variadic functions, without any wrapper needed.

@taralx Thanks for the PR! Could you please adapt it to call the variadic function directly, without a C wrapper?