use std::ffi::CString;
use crate::util::Binding;
use crate::{raw, Buf, ConfigLevel, Error, IntoCString};
pub unsafe fn set_search_path<P>(level: ConfigLevel, path: P) -> Result<(), Error>
where
P: IntoCString,
{
crate::init();
try_call!(raw::git_libgit2_opts(
raw::GIT_OPT_SET_SEARCH_PATH as libc::c_int,
level as libc::c_int,
path.into_c_string()?.as_ptr()
));
Ok(())
}
pub unsafe fn reset_search_path(level: ConfigLevel) -> Result<(), Error> {
crate::init();
try_call!(raw::git_libgit2_opts(
raw::GIT_OPT_SET_SEARCH_PATH as libc::c_int,
level as libc::c_int,
core::ptr::null::<u8>()
));
Ok(())
}
pub unsafe fn get_search_path(level: ConfigLevel) -> Result<CString, Error> {
crate::init();
let buf = Buf::new();
try_call!(raw::git_libgit2_opts(
raw::GIT_OPT_GET_SEARCH_PATH as libc::c_int,
level as libc::c_int,
buf.raw() as *const _
));
buf.into_c_string()
}
pub fn strict_object_creation(enabled: bool) {
let error = unsafe {
raw::git_libgit2_opts(
raw::GIT_OPT_ENABLE_STRICT_OBJECT_CREATION as libc::c_int,
enabled as libc::c_int,
)
};
debug_assert!(error >= 0);
}
pub fn strict_hash_verification(enabled: bool) {
let error = unsafe {
raw::git_libgit2_opts(
raw::GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION as libc::c_int,
enabled as libc::c_int,
)
};
debug_assert!(error >= 0);
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn smoke() {
strict_hash_verification(false);
}
}