Skip to content

Commit 4c982fb

Browse files
committed
Add bindings for cache size options
1 parent d58c7ce commit 4c982fb

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/opts.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,41 @@ pub unsafe fn set_cache_object_limit(kind: ObjectType, size: libc::size_t) -> Re
111111
Ok(())
112112
}
113113

114+
/// Set the maximum total data size that will be cached in memory across all
115+
/// repositories before libgit2 starts evicting objects from the cache. This
116+
/// is a soft limit, in that the library might briefly exceed it, but will start
117+
/// aggressively evicting objects from cache when that happens. The default
118+
/// cache size is 256MB.
119+
///
120+
/// # Safety
121+
/// This function is modifying a C global without synchronization, so it is not
122+
/// thread safe, and should only be called before any thread is spawned.
123+
pub unsafe fn set_cache_max_size(size: libc::size_t) -> Result<(), Error> {
124+
crate::init();
125+
try_call!(raw::git_libgit2_opts(
126+
raw::GIT_OPT_SET_CACHE_MAX_SIZE as libc::c_int,
127+
size
128+
));
129+
Ok(())
130+
}
131+
132+
/// Get the current bytes in cache and the maximum that would be allowed in the cache.
133+
///
134+
/// # Safety
135+
/// This function is reading a C global without synchronization, so it is not
136+
/// thread safe, and should only be called before any thread is spawned.
137+
pub unsafe fn get_cached_memory() -> Result<(libc::size_t, libc::size_t), Error> {
138+
crate::init();
139+
let mut current = 0;
140+
let mut allowed = 0;
141+
try_call!(raw::git_libgit2_opts(
142+
raw::GIT_OPT_GET_CACHED_MEMORY as libc::c_int,
143+
&mut current,
144+
&mut allowed
145+
));
146+
Ok((current, allowed))
147+
}
148+
114149
/// Controls whether or not libgit2 will verify when writing an object that all
115150
/// objects it references are valid. Enabled by default, but disabling this can
116151
/// significantly improve performance, at the cost of potentially allowing the

0 commit comments

Comments
 (0)