Skip to content

Commit 0313adc

Browse files
authored
Provide a binding for GIT_OPT_ENABLE_STRICT_OBJECT_CREATION (#638)
* Simplify handling of bool option Rust supports converting a bool to a 0/1 integer via `as`, so we don't need to use an if. * Provide a binding for GIT_OPT_ENABLE_STRICT_OBJECT_CREATION
1 parent 2ba1852 commit 0313adc

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/opts.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
22
33
use crate::raw;
44

5+
/// Controls whether or not libgit2 will verify when writing an object that all
6+
/// objects it references are valid. Enabled by default, but disabling this can
7+
/// significantly improve performance, at the cost of potentially allowing the
8+
/// creation of objects that reference invalid objects (due to programming
9+
/// error or repository corruption).
10+
pub fn strict_object_creation(enabled: bool) {
11+
let error = unsafe {
12+
raw::git_libgit2_opts(
13+
raw::GIT_OPT_ENABLE_STRICT_OBJECT_CREATION as libc::c_int,
14+
enabled as libc::c_int,
15+
)
16+
};
17+
// This function cannot actually fail, but the function has an error return
18+
// for other options that can.
19+
debug_assert!(error >= 0);
20+
}
21+
522
/// Controls whether or not libgit2 will verify that objects loaded have the
623
/// expected hash. Enabled by default, but disabling this can significantly
724
/// improve performance, at the cost of relying on repository integrity
@@ -10,7 +27,7 @@ pub fn strict_hash_verification(enabled: bool) {
1027
let error = unsafe {
1128
raw::git_libgit2_opts(
1229
raw::GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION as libc::c_int,
13-
if enabled { 1 } else { 0 } as libc::c_int,
30+
enabled as libc::c_int,
1431
)
1532
};
1633
// This function cannot actually fail, but the function has an error return

0 commit comments

Comments
 (0)