@@ -5,7 +5,7 @@ use std::ptr;
5
5
6
6
use crate :: string_array:: StringArray ;
7
7
use crate :: util:: Binding ;
8
- use crate :: { raw, Buf , ConfigLevel , Error , IntoCString } ;
8
+ use crate :: { raw, Buf , ConfigLevel , Error , IntoCString , ObjectType } ;
9
9
10
10
/// Set the search path for a level of config data. The search path applied to
11
11
/// shared attributes and ignore files, too.
@@ -89,6 +89,28 @@ pub fn enable_caching(enabled: bool) {
89
89
debug_assert ! ( error >= 0 ) ;
90
90
}
91
91
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
+
92
114
/// Controls whether or not libgit2 will verify when writing an object that all
93
115
/// objects it references are valid. Enabled by default, but disabling this can
94
116
/// significantly improve performance, at the cost of potentially allowing the
0 commit comments