Skip to content

Commit

Permalink
Add bindings for mwindow opts
Browse files Browse the repository at this point in the history
  • Loading branch information
rpelliard committed Mar 11, 2024
1 parent 3da58f3 commit 8d18374
Showing 1 changed file with 111 additions and 0 deletions.
111 changes: 111 additions & 0 deletions src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,99 @@ where
Ok(())
}

/// Get the maximum mmap window size
pub fn get_mwindow_size() -> Result<usize, Error> {
crate::init();

let mut size = 0;

unsafe {
try_call!(raw::git_libgit2_opts(
raw::GIT_OPT_GET_MWINDOW_SIZE as libc::c_int,
&mut size
));
}

Ok(size)
}

/// Set the maximum mmap window size
pub fn set_mwindow_size(size: usize) -> Result<(), Error> {
crate::init();

unsafe {
try_call!(raw::git_libgit2_opts(
raw::GIT_OPT_SET_MWINDOW_SIZE as libc::c_int,
size
));
}

Ok(())
}

/// Get the maximum memory that will be mapped in total by the library
pub fn get_mwindow_mapped_limit() -> Result<usize, Error> {
crate::init();

let mut limit = 0;

unsafe {
try_call!(raw::git_libgit2_opts(
raw::GIT_OPT_GET_MWINDOW_MAPPED_LIMIT as libc::c_int,
&mut limit
));
}

Ok(limit)
}

/// Set the maximum amount of memory that can be mapped at any time
/// by the library.
pub fn set_mwindow_mapped_limit(limit: usize) -> Result<(), Error> {
crate::init();

unsafe {
try_call!(raw::git_libgit2_opts(
raw::GIT_OPT_SET_MWINDOW_MAPPED_LIMIT as libc::c_int,
limit
));
}

Ok(())
}

/// Get the maximum number of files that will be mapped at any time by the
/// library.
pub fn get_mwindow_file_limit() -> Result<usize, Error> {
crate::init();

let mut limit = 0;

unsafe {
try_call!(raw::git_libgit2_opts(
raw::GIT_OPT_GET_MWINDOW_FILE_LIMIT as libc::c_int,
&mut limit
));
}

Ok(limit)
}

/// Set the maximum number of files that can be mapped at any time
/// by the library. The default (0) is unlimited.
pub fn set_mwindow_file_limit(limit: usize) -> Result<(), Error> {
crate::init();

unsafe {
try_call!(raw::git_libgit2_opts(
raw::GIT_OPT_SET_MWINDOW_FILE_LIMIT as libc::c_int,
limit
));
}

Ok(())
}

#[cfg(test)]
mod test {
use super::*;
Expand All @@ -241,4 +334,22 @@ mod test {
fn smoke() {
strict_hash_verification(false);
}

#[test]
fn mwindow_size() {
assert!(set_mwindow_size(1024).is_ok());
assert!(get_mwindow_size().unwrap() == 1024);
}

#[test]
fn mwindow_mapped_limit() {
assert!(set_mwindow_mapped_limit(1024).is_ok());
assert!(get_mwindow_mapped_limit().unwrap() == 1024);
}

#[test]
fn mwindow_file_limit() {
assert!(set_mwindow_file_limit(1024).is_ok());
assert!(get_mwindow_file_limit().unwrap() == 1024);
}
}

0 comments on commit 8d18374

Please sign in to comment.