Skip to content

Commit 3778952

Browse files
authored
Merge pull request #1035 from rpelliard/mwindow-opts
Add bindings for mwindow opts
2 parents a75e007 + 68880b2 commit 3778952

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed

src/opts.rs

+129
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,111 @@ where
233233
Ok(())
234234
}
235235

236+
/// Get the maximum mmap window size
237+
///
238+
/// # Safety
239+
/// This function is reading a C global without synchronization, so it is not
240+
/// thread safe, and should only be called before any thread is spawned.
241+
pub unsafe fn get_mwindow_size() -> Result<libc::size_t, Error> {
242+
crate::init();
243+
244+
let mut size = 0;
245+
246+
try_call!(raw::git_libgit2_opts(
247+
raw::GIT_OPT_GET_MWINDOW_SIZE as libc::c_int,
248+
&mut size
249+
));
250+
251+
Ok(size)
252+
}
253+
254+
/// Set the maximum mmap window size
255+
///
256+
/// # Safety
257+
/// This function is modifying a C global without synchronization, so it is not
258+
/// thread safe, and should only be called before any thread is spawned.
259+
pub unsafe fn set_mwindow_size(size: libc::size_t) -> Result<(), Error> {
260+
crate::init();
261+
262+
try_call!(raw::git_libgit2_opts(
263+
raw::GIT_OPT_SET_MWINDOW_SIZE as libc::c_int,
264+
size
265+
));
266+
267+
Ok(())
268+
}
269+
270+
/// Get the maximum memory that will be mapped in total by the library
271+
///
272+
/// # Safety
273+
/// This function is reading a C global without synchronization, so it is not
274+
/// thread safe, and should only be called before any thread is spawned.
275+
pub unsafe fn get_mwindow_mapped_limit() -> Result<libc::size_t, Error> {
276+
crate::init();
277+
278+
let mut limit = 0;
279+
280+
try_call!(raw::git_libgit2_opts(
281+
raw::GIT_OPT_GET_MWINDOW_MAPPED_LIMIT as libc::c_int,
282+
&mut limit
283+
));
284+
285+
Ok(limit)
286+
}
287+
288+
/// Set the maximum amount of memory that can be mapped at any time
289+
/// by the library.
290+
///
291+
/// # Safety
292+
/// This function is modifying a C global without synchronization, so it is not
293+
/// thread safe, and should only be called before any thread is spawned.
294+
pub unsafe fn set_mwindow_mapped_limit(limit: libc::size_t) -> Result<(), Error> {
295+
crate::init();
296+
297+
try_call!(raw::git_libgit2_opts(
298+
raw::GIT_OPT_SET_MWINDOW_MAPPED_LIMIT as libc::c_int,
299+
limit
300+
));
301+
302+
Ok(())
303+
}
304+
305+
/// Get the maximum number of files that will be mapped at any time by the
306+
/// library.
307+
///
308+
/// # Safety
309+
/// This function is reading a C global without synchronization, so it is not
310+
/// thread safe, and should only be called before any thread is spawned.
311+
pub unsafe fn get_mwindow_file_limit() -> Result<libc::size_t, Error> {
312+
crate::init();
313+
314+
let mut limit = 0;
315+
316+
try_call!(raw::git_libgit2_opts(
317+
raw::GIT_OPT_GET_MWINDOW_FILE_LIMIT as libc::c_int,
318+
&mut limit
319+
));
320+
321+
Ok(limit)
322+
}
323+
324+
/// Set the maximum number of files that can be mapped at any time
325+
/// by the library. The default (0) is unlimited.
326+
///
327+
/// # Safety
328+
/// This function is modifying a C global without synchronization, so it is not
329+
/// thread safe, and should only be called before any thread is spawned.
330+
pub unsafe fn set_mwindow_file_limit(limit: libc::size_t) -> Result<(), Error> {
331+
crate::init();
332+
333+
try_call!(raw::git_libgit2_opts(
334+
raw::GIT_OPT_SET_MWINDOW_FILE_LIMIT as libc::c_int,
335+
limit
336+
));
337+
338+
Ok(())
339+
}
340+
236341
#[cfg(test)]
237342
mod test {
238343
use super::*;
@@ -241,4 +346,28 @@ mod test {
241346
fn smoke() {
242347
strict_hash_verification(false);
243348
}
349+
350+
#[test]
351+
fn mwindow_size() {
352+
unsafe {
353+
assert!(set_mwindow_size(1024).is_ok());
354+
assert!(get_mwindow_size().unwrap() == 1024);
355+
}
356+
}
357+
358+
#[test]
359+
fn mwindow_mapped_limit() {
360+
unsafe {
361+
assert!(set_mwindow_mapped_limit(1024).is_ok());
362+
assert!(get_mwindow_mapped_limit().unwrap() == 1024);
363+
}
364+
}
365+
366+
#[test]
367+
fn mwindow_file_limit() {
368+
unsafe {
369+
assert!(set_mwindow_file_limit(1024).is_ok());
370+
assert!(get_mwindow_file_limit().unwrap() == 1024);
371+
}
372+
}
244373
}

0 commit comments

Comments
 (0)