Skip to content

Commit 29df92d

Browse files
committed
Add binding for GIT_OPT_SET_CACHE_OBJECT_LIMIT
1 parent 8152297 commit 29df92d

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/opts.rs

+20-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,25 @@ 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+
pub fn set_cache_object_limit(kind: ObjectType, size: libc::size_t) {
98+
crate::init();
99+
let error = unsafe {
100+
raw::git_libgit2_opts(
101+
raw::GIT_OPT_SET_CACHE_OBJECT_LIMIT as libc::c_int,
102+
kind as libc::c_int,
103+
size,
104+
)
105+
};
106+
// This function cannot actually fail, but the function has an error return
107+
// for other options that can.
108+
debug_assert!(error >= 0);
109+
}
110+
92111
/// Controls whether or not libgit2 will verify when writing an object that all
93112
/// objects it references are valid. Enabled by default, but disabling this can
94113
/// significantly improve performance, at the cost of potentially allowing the

0 commit comments

Comments
 (0)