Skip to content

Add binding for GIT_OPT_SET_CACHE_OBJECT_LIMIT #1118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::ptr;

use crate::string_array::StringArray;
use crate::util::Binding;
use crate::{raw, Buf, ConfigLevel, Error, IntoCString};
use crate::{raw, Buf, ConfigLevel, Error, IntoCString, ObjectType};

/// Set the search path for a level of config data. The search path applied to
/// shared attributes and ignore files, too.
Expand Down Expand Up @@ -89,6 +89,28 @@ pub fn enable_caching(enabled: bool) {
debug_assert!(error >= 0);
}

/// Set the maximum data size for the given type of object to be considered
/// eligible for caching in memory. Setting to value to zero means that that
/// type of object will not be cached. Defaults to 0 for [`ObjectType::Blob`]
/// (i.e. won't cache blobs) and 4k for [`ObjectType::Commit`],
/// [`ObjectType::Tree`], and [`ObjectType::Tag`].
///
/// `kind` must be one of [`ObjectType::Blob`], [`ObjectType::Commit`],
/// [`ObjectType::Tree`], and [`ObjectType::Tag`].
///
/// # Safety
/// This function is modifying a C global without synchronization, so it is not
/// thread safe, and should only be called before any thread is spawned.
pub unsafe fn set_cache_object_limit(kind: ObjectType, size: libc::size_t) -> Result<(), Error> {
crate::init();
try_call!(raw::git_libgit2_opts(
raw::GIT_OPT_SET_CACHE_OBJECT_LIMIT as libc::c_int,
kind as libc::c_int,
size
));
Ok(())
}

/// Controls whether or not libgit2 will verify when writing an object that all
/// objects it references are valid. Enabled by default, but disabling this can
/// significantly improve performance, at the cost of potentially allowing the
Expand Down
Loading