Skip to content

Commit 2c67635

Browse files
authored
Provide a function to modify the GIT_OPT_ENABLE_CACHING option (#783)
1 parent 4979a86 commit 2c67635

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/opts.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,23 @@ pub unsafe fn get_search_path(level: ConfigLevel) -> Result<CString, Error> {
6969
buf.into_c_string()
7070
}
7171

72+
/// Controls whether or not libgit2 will cache loaded objects. Enabled by
73+
/// default, but disabling this can improve performance and memory usage if
74+
/// loading a large number of objects that will not be referenced again.
75+
/// Disabling this will cause repository objects to clear their caches when next
76+
/// accessed.
77+
pub fn enable_caching(enabled: bool) {
78+
let error = unsafe {
79+
raw::git_libgit2_opts(
80+
raw::GIT_OPT_ENABLE_CACHING as libc::c_int,
81+
enabled as libc::c_int,
82+
)
83+
};
84+
// This function cannot actually fail, but the function has an error return
85+
// for other options that can.
86+
debug_assert!(error >= 0);
87+
}
88+
7289
/// Controls whether or not libgit2 will verify when writing an object that all
7390
/// objects it references are valid. Enabled by default, but disabling this can
7491
/// significantly improve performance, at the cost of potentially allowing the

0 commit comments

Comments
 (0)