summaryrefslogtreecommitdiff
path: root/src/pack.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2018-12-17 09:10:53 +0100
committerPatrick Steinhardt <ps@pks.im>2019-02-15 13:16:48 +0100
commitb9d0b664071fed96e690a70ee4472facf554eb70 (patch)
tree2507c85e58c49d378a028c7b571d98fe3809f4f3 /src/pack.c
parentaa2456239b4644c43d3cc9e002ed718e5078e7cc (diff)
downloadlibgit2-b9d0b664071fed96e690a70ee4472facf554eb70.tar.gz
offmap: introduce high-level setter for key/value pairs
Currently, there is only one caller that adds entries into an offset map, and this caller first uses `git_offmap_put` to add a key and then set the value at the returned index by using `git_offmap_set_value_at`. This is just too tighlty coupled with implementation details of the map as it exposes the index of inserted entries, which we really do not care about at all. Introduce a new function `git_offmap_set`, which takes as parameters the map, key and value and directly returns an error code. Convert the caller to make use of it instead.
Diffstat (limited to 'src/pack.c')
-rw-r--r--src/pack.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/src/pack.c b/src/pack.c
index ab78d3f61..c9d5602cd 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -147,8 +147,7 @@ static int cache_add(
git_off_t offset)
{
git_pack_cache_entry *entry;
- int error, exists = 0;
- size_t k;
+ int exists;
if (base->len > GIT_PACK_CACHE_SIZE_LIMIT)
return -1;
@@ -166,9 +165,7 @@ static int cache_add(
while (cache->memory_used + base->len > cache->memory_limit)
free_lowest_entry(cache);
- k = git_offmap_put(cache->entries, offset, &error);
- assert(error != 0);
- git_offmap_set_value_at(cache->entries, k, entry);
+ git_offmap_set(cache->entries, offset, entry);
cache->memory_used += entry->raw.len;
*cached_out = entry;