Commit ee12272d by Vicent Marti

Global option setters

parent e183e375
......@@ -131,6 +131,8 @@ enum {
GIT_OPT_SET_MWINDOW_MAPPED_LIMIT,
GIT_OPT_GET_SEARCH_PATH,
GIT_OPT_SET_SEARCH_PATH,
GIT_OPT_SET_CACHE_LIMIT,
GIT_OPT_ENABLE_CACHING
};
/**
......
......@@ -17,6 +17,8 @@
GIT__USE_OIDMAP
bool git_cache__enabled = true;
size_t git_cache__max_object_size[8] = {
0, /* GIT_OBJ__EXT1 */
4096, /* GIT_OBJ_COMMIT */
......@@ -109,11 +111,7 @@ static void cache_evict_entries(git_cache *cache, size_t evict_count)
static bool cache_should_store(git_otype object_type, size_t object_size)
{
size_t max_size = git_cache__max_object_size[object_type];
if (max_size == 0 || object_size > max_size)
return false;
return true;
return git_cache__enabled && object_size < max_size;
}
static void *cache_get(git_cache *cache, const git_oid *oid, unsigned int flags)
......@@ -121,7 +119,7 @@ static void *cache_get(git_cache *cache, const git_oid *oid, unsigned int flags)
khiter_t pos;
git_cached_obj *entry = NULL;
if (git_mutex_lock(&cache->lock) < 0)
if (!git_cache__enabled || git_mutex_lock(&cache->lock) < 0)
return NULL;
pos = kh_get(oid, cache->map, oid);
......
......@@ -20,6 +20,9 @@ enum {
GIT_CACHE_STORE_PARSED = 2
};
extern bool git_cache__enabled;
extern size_t git_cache__max_object_size[8];
typedef struct {
git_oid oid;
int16_t type;
......
......@@ -11,6 +11,7 @@
#include <ctype.h>
#include "posix.h"
#include "fileops.h"
#include "cache.h"
#ifdef _MSC_VER
# include <Shlwapi.h>
......@@ -93,6 +94,16 @@ int git_libgit2_opts(int key, ...)
if ((error = config_level_to_futils_dir(va_arg(ap, int))) >= 0)
error = git_futils_dirs_set(error, va_arg(ap, const char *));
break;
case GIT_OPT_SET_CACHE_LIMIT: {
git_otype type = (git_otype)va_arg(ap, int);
git_cache__max_object_size[type] = va_arg(ap, size_t);
break;
}
case GIT_OPT_ENABLE_CACHING:
git_cache__enabled = va_arg(ap, int);
break;
}
va_end(ap);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment