Skip to content

Commit 20b1713

Browse files
taralxjoshtriplett
authored andcommitted
Add git2::opts::strict_hash_verification
1 parent d7757f1 commit 20b1713

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

libgit2-sys/lib.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,6 +1778,42 @@ git_enum! {
17781778
}
17791779
}
17801780

1781+
git_enum! {
1782+
pub enum git_libgit2_opt_t {
1783+
GIT_OPT_GET_MWINDOW_SIZE = 0,
1784+
GIT_OPT_SET_MWINDOW_SIZE,
1785+
GIT_OPT_GET_MWINDOW_MAPPED_LIMIT,
1786+
GIT_OPT_SET_MWINDOW_MAPPED_LIMIT,
1787+
GIT_OPT_GET_SEARCH_PATH,
1788+
GIT_OPT_SET_SEARCH_PATH,
1789+
GIT_OPT_SET_CACHE_OBJECT_LIMIT,
1790+
GIT_OPT_SET_CACHE_MAX_SIZE,
1791+
GIT_OPT_ENABLE_CACHING,
1792+
GIT_OPT_GET_CACHED_MEMORY,
1793+
GIT_OPT_GET_TEMPLATE_PATH,
1794+
GIT_OPT_SET_TEMPLATE_PATH,
1795+
GIT_OPT_SET_SSL_CERT_LOCATIONS,
1796+
GIT_OPT_SET_USER_AGENT,
1797+
GIT_OPT_ENABLE_STRICT_OBJECT_CREATION,
1798+
GIT_OPT_ENABLE_STRICT_SYMBOLIC_REF_CREATION,
1799+
GIT_OPT_SET_SSL_CIPHERS,
1800+
GIT_OPT_GET_USER_AGENT,
1801+
GIT_OPT_ENABLE_OFS_DELTA,
1802+
GIT_OPT_ENABLE_FSYNC_GITDIR,
1803+
GIT_OPT_GET_WINDOWS_SHAREMODE,
1804+
GIT_OPT_SET_WINDOWS_SHAREMODE,
1805+
GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION,
1806+
GIT_OPT_SET_ALLOCATOR,
1807+
GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY,
1808+
GIT_OPT_GET_PACK_MAX_OBJECTS,
1809+
GIT_OPT_SET_PACK_MAX_OBJECTS,
1810+
GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS,
1811+
GIT_OPT_ENABLE_HTTP_EXPECT_CONTINUE,
1812+
GIT_OPT_GET_MWINDOW_FILE_LIMIT,
1813+
GIT_OPT_SET_MWINDOW_FILE_LIMIT,
1814+
}
1815+
}
1816+
17811817
extern "C" {
17821818
// threads
17831819
pub fn git_libgit2_init() -> c_int;
@@ -3722,6 +3758,8 @@ extern "C" {
37223758
commit: *mut git_commit,
37233759
given_opts: *const git_revert_options,
37243760
) -> c_int;
3761+
3762+
pub fn git_libgit2_opts(option: c_int, ...) -> c_int;
37253763
}
37263764

37273765
pub fn init() {

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ mod util;
638638
pub mod build;
639639
pub mod cert;
640640
pub mod oid_array;
641+
pub mod opts;
641642
pub mod string_array;
642643
pub mod transport;
643644

src/opts.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//! Bindings to libgit2's git_libgit2_opts function.
2+
3+
use crate::raw;
4+
5+
/// Controls whether or not libgit2 will verify that objects loaded have the
6+
/// expected hash. Enabled by default, but disabling this can significantly
7+
/// improve performance at the cost of correctness.
8+
pub fn strict_hash_verification(enabled: bool) {
9+
let error = unsafe {
10+
raw::git_libgit2_opts(
11+
raw::GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION as libc::c_int,
12+
if enabled { 1 } else { 0 } as libc::c_int,
13+
)
14+
};
15+
// This function cannot actually fail, but the function has an error return
16+
// for other options that can.
17+
debug_assert!(error >= 0);
18+
}
19+
20+
#[cfg(test)]
21+
mod test {
22+
#[test]
23+
fn smoke() {
24+
super::strict_hash_verification(false);
25+
}
26+
}

0 commit comments

Comments
 (0)