@@ -233,6 +233,99 @@ where
233233 Ok ( ( ) )
234234}
235235
236+ /// Get the maximum mmap window size
237+ pub fn get_mwindow_size ( ) -> Result < usize , Error > {
238+ crate :: init ( ) ;
239+
240+ let mut size = 0 ;
241+
242+ unsafe {
243+ try_call ! ( raw:: git_libgit2_opts(
244+ raw:: GIT_OPT_GET_MWINDOW_SIZE as libc:: c_int,
245+ & mut size
246+ ) ) ;
247+ }
248+
249+ Ok ( size)
250+ }
251+
252+ /// Set the maximum mmap window size
253+ pub fn set_mwindow_size ( size : usize ) -> Result < ( ) , Error > {
254+ crate :: init ( ) ;
255+
256+ unsafe {
257+ try_call ! ( raw:: git_libgit2_opts(
258+ raw:: GIT_OPT_SET_MWINDOW_SIZE as libc:: c_int,
259+ size
260+ ) ) ;
261+ }
262+
263+ Ok ( ( ) )
264+ }
265+
266+ /// Get the maximum memory that will be mapped in total by the library
267+ pub fn get_mwindow_mapped_limit ( ) -> Result < usize , Error > {
268+ crate :: init ( ) ;
269+
270+ let mut limit = 0 ;
271+
272+ unsafe {
273+ try_call ! ( raw:: git_libgit2_opts(
274+ raw:: GIT_OPT_GET_MWINDOW_MAPPED_LIMIT as libc:: c_int,
275+ & mut limit
276+ ) ) ;
277+ }
278+
279+ Ok ( limit)
280+ }
281+
282+ /// Set the maximum amount of memory that can be mapped at any time
283+ /// by the library.
284+ pub fn set_mwindow_mapped_limit ( limit : usize ) -> Result < ( ) , Error > {
285+ crate :: init ( ) ;
286+
287+ unsafe {
288+ try_call ! ( raw:: git_libgit2_opts(
289+ raw:: GIT_OPT_SET_MWINDOW_MAPPED_LIMIT as libc:: c_int,
290+ limit
291+ ) ) ;
292+ }
293+
294+ Ok ( ( ) )
295+ }
296+
297+ /// Get the maximum number of files that will be mapped at any time by the
298+ /// library.
299+ pub fn get_mwindow_file_limit ( ) -> Result < usize , Error > {
300+ crate :: init ( ) ;
301+
302+ let mut limit = 0 ;
303+
304+ unsafe {
305+ try_call ! ( raw:: git_libgit2_opts(
306+ raw:: GIT_OPT_GET_MWINDOW_FILE_LIMIT as libc:: c_int,
307+ & mut limit
308+ ) ) ;
309+ }
310+
311+ Ok ( limit)
312+ }
313+
314+ /// Set the maximum number of files that can be mapped at any time
315+ /// by the library. The default (0) is unlimited.
316+ pub fn set_mwindow_file_limit ( limit : usize ) -> Result < ( ) , Error > {
317+ crate :: init ( ) ;
318+
319+ unsafe {
320+ try_call ! ( raw:: git_libgit2_opts(
321+ raw:: GIT_OPT_SET_MWINDOW_FILE_LIMIT as libc:: c_int,
322+ limit
323+ ) ) ;
324+ }
325+
326+ Ok ( ( ) )
327+ }
328+
236329#[ cfg( test) ]
237330mod test {
238331 use super :: * ;
@@ -241,4 +334,22 @@ mod test {
241334 fn smoke ( ) {
242335 strict_hash_verification ( false ) ;
243336 }
337+
338+ #[ test]
339+ fn mwindow_size ( ) {
340+ assert ! ( set_mwindow_size( 1024 ) . is_ok( ) ) ;
341+ assert ! ( get_mwindow_size( ) . unwrap( ) == 1024 ) ;
342+ }
343+
344+ #[ test]
345+ fn mwindow_mapped_limit ( ) {
346+ assert ! ( set_mwindow_mapped_limit( 1024 ) . is_ok( ) ) ;
347+ assert ! ( get_mwindow_mapped_limit( ) . unwrap( ) == 1024 ) ;
348+ }
349+
350+ #[ test]
351+ fn mwindow_file_limit ( ) {
352+ assert ! ( set_mwindow_file_limit( 1024 ) . is_ok( ) ) ;
353+ assert ! ( get_mwindow_file_limit( ) . unwrap( ) == 1024 ) ;
354+ }
244355}
0 commit comments