Per-object filtering
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
diff --git a/src/cache.c b/src/cache.c
index 6eb18da..a0925a1 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -17,8 +17,22 @@
GIT__USE_OIDMAP
+bool git_cache__store_types[8] = {
+ false, /* GIT_OBJ__EXT1 */
+ true, /* GIT_OBJ_COMMIT */
+ true, /* GIT_OBJ_TREE */
+ false, /* GIT_OBJ_BLOB */
+ true, /* GIT_OBJ_TAG */
+ false, /* GIT_OBJ__EXT2 */
+ false, /* GIT_OBJ_OFS_DELTA */
+ false /* GIT_OBJ_REF_DELTA */
+};
+
+size_t git_cache__max_object_size = 4096;
+
int git_cache_init(git_cache *cache)
{
+ cache->lru_count = 0;
cache->map = git_oidmap_alloc();
git_mutex_init(&cache->lock);
return 0;
@@ -30,8 +44,14 @@ void git_cache_free(git_cache *cache)
git_mutex_free(&cache->lock);
}
-static bool cache_should_store(git_cached_obj *entry)
+static bool cache_should_store(git_otype object_type, size_t object_size)
{
+ if (!git_cache__store_types[object_type])
+ return false;
+
+ if (object_size > git_cache__max_object_size)
+ return false;
+
return true;
}
@@ -63,11 +83,6 @@ static void *cache_store(git_cache *cache, git_cached_obj *entry)
{
khiter_t pos;
- git_cached_obj_incref(entry);
-
- if (!cache_should_store(entry))
- return entry;
-
if (git_mutex_lock(&cache->lock) < 0)
return entry;
@@ -110,12 +125,22 @@ static void *cache_store(git_cache *cache, git_cached_obj *entry)
void *git_cache_store_raw(git_cache *cache, git_odb_object *entry)
{
+ git_cached_obj_incref(entry);
+
+ if (!cache_should_store(entry->raw.type, entry->raw.len))
+ return entry;
+
entry->cached.flags = GIT_CACHE_STORE_RAW;
return cache_store(cache, (git_cached_obj *)entry);
}
void *git_cache_store_parsed(git_cache *cache, git_object *entry)
{
+ git_cached_obj_incref(entry);
+
+ if (!cache_should_store(entry->type, 0 /* TODO */))
+ return entry;
+
entry->cached.flags = GIT_CACHE_STORE_PARSED;
return cache_store(cache, (git_cached_obj *)entry);
}
diff --git a/src/cache.h b/src/cache.h
index f30af9c..3461ff7 100644
--- a/src/cache.h
+++ b/src/cache.h
@@ -23,7 +23,8 @@ enum {
typedef struct {
git_oid oid;
git_atomic refcount;
- uint32_t flags;
+ uint16_t flags;
+ uint16_t lru;
} git_cached_obj;
typedef struct {