summaryrefslogtreecommitdiff
path: root/src/pack-objects.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2018-12-17 09:01:53 +0100
committerPatrick Steinhardt <ps@pks.im>2019-02-15 13:16:48 +0100
commit9694ef2064be3ecc3f173af296ab091f0498234d (patch)
tree9e06665418a72beab80ed6ce57cf23461707a811 /src/pack-objects.c
parent03555830784a2856e0c9651d2643b3ee5ce2084d (diff)
downloadlibgit2-9694ef2064be3ecc3f173af296ab091f0498234d.tar.gz
oidmap: introduce high-level getter for values
The current way of looking up an entry from a map is tightly coupled with the map implementation, as one first has to look up the index of the key and then retrieve the associated value by using the index. As a caller, you usually do not care about any indices at all, though, so this is more complicated than really necessary. Furthermore, it invites for errors to happen if the correct error checking sequence is not being followed. Introduce a new high-level function `git_oidmap_get` that takes a map and a key and returns a pointer to the associated value if such a key exists. Otherwise, a `NULL` pointer is returned. Adjust all callers that can trivially be converted.
Diffstat (limited to 'src/pack-objects.c')
-rw-r--r--src/pack-objects.c13
1 files changed, 3 insertions, 10 deletions
diff --git a/src/pack-objects.c b/src/pack-objects.c
index 4ccc84d4b..094317a80 100644
--- a/src/pack-objects.c
+++ b/src/pack-objects.c
@@ -512,15 +512,12 @@ static int cb_tag_foreach(const char *name, git_oid *oid, void *data)
{
git_packbuilder *pb = data;
git_pobject *po;
- size_t pos;
GIT_UNUSED(name);
- pos = git_oidmap_lookup_index(pb->object_ix, oid);
- if (!git_oidmap_valid_index(pb->object_ix, pos))
+ if ((po = git_oidmap_get(pb->object_ix, oid)) == NULL)
return 0;
- po = git_oidmap_value_at(pb->object_ix, pos);
po->tagged = 1;
/* TODO: peel objects */
@@ -1537,14 +1534,10 @@ static int lookup_walk_object(struct walk_object **out, git_packbuilder *pb, con
static int retrieve_object(struct walk_object **out, git_packbuilder *pb, const git_oid *id)
{
- int error;
- size_t pos;
struct walk_object *obj;
+ int error;
- pos = git_oidmap_lookup_index(pb->walk_objects, id);
- if (git_oidmap_valid_index(pb->walk_objects, pos)) {
- obj = git_oidmap_value_at(pb->walk_objects, pos);
- } else {
+ if ((obj = git_oidmap_get(pb->walk_objects, id)) == NULL) {
if ((error = lookup_walk_object(&obj, pb, id)) < 0)
return error;