Skip to content

Commit 10771e4

Browse files
authored
Merge pull request #1118 from qaqland/add-opts
Add binding for GIT_OPT_SET_CACHE_OBJECT_LIMIT
2 parents c737cea + f0a296c commit 10771e4

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/opts.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::ptr;
55

66
use crate::string_array::StringArray;
77
use crate::util::Binding;
8-
use crate::{raw, Buf, ConfigLevel, Error, IntoCString};
8+
use crate::{raw, Buf, ConfigLevel, Error, IntoCString, ObjectType};
99

1010
/// Set the search path for a level of config data. The search path applied to
1111
/// shared attributes and ignore files, too.
@@ -89,6 +89,28 @@ pub fn enable_caching(enabled: bool) {
8989
debug_assert!(error >= 0);
9090
}
9191

92+
/// Set the maximum data size for the given type of object to be considered
93+
/// eligible for caching in memory. Setting to value to zero means that that
94+
/// type of object will not be cached. Defaults to 0 for [`ObjectType::Blob`]
95+
/// (i.e. won't cache blobs) and 4k for [`ObjectType::Commit`],
96+
/// [`ObjectType::Tree`], and [`ObjectType::Tag`].
97+
///
98+
/// `kind` must be one of [`ObjectType::Blob`], [`ObjectType::Commit`],
99+
/// [`ObjectType::Tree`], and [`ObjectType::Tag`].
100+
///
101+
/// # Safety
102+
/// This function is modifying a C global without synchronization, so it is not
103+
/// thread safe, and should only be called before any thread is spawned.
104+
pub unsafe fn set_cache_object_limit(kind: ObjectType, size: libc::size_t) -> Result<(), Error> {
105+
crate::init();
106+
try_call!(raw::git_libgit2_opts(
107+
raw::GIT_OPT_SET_CACHE_OBJECT_LIMIT as libc::c_int,
108+
kind as libc::c_int,
109+
size
110+
));
111+
Ok(())
112+
}
113+
92114
/// Controls whether or not libgit2 will verify when writing an object that all
93115
/// objects it references are valid. Enabled by default, but disabling this can
94116
/// significantly improve performance, at the cost of potentially allowing the

0 commit comments

Comments
 (0)