diff options
| author | Russell Belfer <rb@github.com> | 2013-04-12 12:44:51 -0700 |
|---|---|---|
| committer | Vicent Marti <tanoku@gmail.com> | 2013-04-22 16:50:51 +0200 |
| commit | b12b72ea82776bbbd4296eeac1376055b0487edf (patch) | |
| tree | 193ea7ff5f0a026c6157663cc9e181df3c3da364 /src/cache.c | |
| parent | badd85a61354ef7b62c5f8e53d740738e5ef1e57 (diff) | |
| download | libgit2-b12b72ea82776bbbd4296eeac1376055b0487edf.tar.gz | |
Add range checking around cache opts
Add a git_cache_set_max_object_size method that does more checking
around setting the max object size. Also add a git_cache_size to
read the number of objects currently in the cache. This makes it
easier to write tests.
Diffstat (limited to 'src/cache.c')
| -rw-r--r-- | src/cache.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/cache.c b/src/cache.c index f8cddeaca..263f736fa 100644 --- a/src/cache.c +++ b/src/cache.c @@ -19,17 +19,28 @@ GIT__USE_OIDMAP bool git_cache__enabled = true; -size_t git_cache__max_object_size[8] = { - 0, /* GIT_OBJ__EXT1 */ +static size_t git_cache__max_object_size[8] = { + 0, /* GIT_OBJ__EXT1 */ 4096, /* GIT_OBJ_COMMIT */ 4096, /* GIT_OBJ_TREE */ - 0, /* GIT_OBJ_BLOB */ + 0, /* GIT_OBJ_BLOB */ 4096, /* GIT_OBJ_TAG */ - 0, /* GIT_OBJ__EXT2 */ - 0, /* GIT_OBJ_OFS_DELTA */ - 0 /* GIT_OBJ_REF_DELTA */ + 0, /* GIT_OBJ__EXT2 */ + 0, /* GIT_OBJ_OFS_DELTA */ + 0 /* GIT_OBJ_REF_DELTA */ }; +int git_cache_set_max_object_size(git_otype type, size_t size) +{ + if (type < 0 || (size_t)type >= ARRAY_SIZE(git_cache__max_object_size)) { + giterr_set(GITERR_INVALID, "type out of range"); + return -1; + } + + git_cache__max_object_size[type] = size; + return 0; +} + void git_cache_dump_stats(git_cache *cache) { git_cached_obj *object; |
