Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,41 @@ pub unsafe fn set_cache_object_limit(kind: ObjectType, size: libc::size_t) -> Re
Ok(())
}

/// Set the maximum total data size that will be cached in memory across all
/// repositories before libgit2 starts evicting objects from the cache. This
/// is a soft limit, in that the library might briefly exceed it, but will start
/// aggressively evicting objects from cache when that happens. The default
/// cache size is 256MB.
///
/// # Safety
/// This function is modifying a C global without synchronization, so it is not
/// thread safe, and should only be called before any thread is spawned.
pub unsafe fn set_cache_max_size(size: libc::size_t) -> Result<(), Error> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't all of these values be ssize_t (two s's)?

Not that it makes a huge difference, and it's not clear why it is signed, but probably best to match upstream, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally, I missed this ! Thanks for catching

crate::init();
try_call!(raw::git_libgit2_opts(
raw::GIT_OPT_SET_CACHE_MAX_SIZE as libc::c_int,
size
));
Ok(())
}

/// Get the current bytes in cache and the maximum that would be allowed in the cache.
///
/// # Safety
/// This function is reading a C global without synchronization, so it is not
/// thread safe, and should only be called before any thread is spawned.
pub unsafe fn get_cached_memory() -> Result<(libc::size_t, libc::size_t), Error> {
crate::init();
let mut current = 0;
let mut allowed = 0;
try_call!(raw::git_libgit2_opts(
raw::GIT_OPT_GET_CACHED_MEMORY as libc::c_int,
&mut current,
&mut allowed
));
Ok((current, allowed))
}

/// Controls whether or not libgit2 will verify when writing an object that all
/// objects it references are valid. Enabled by default, but disabling this can
/// significantly improve performance, at the cost of potentially allowing the
Expand Down