diff options
| author | Patrick Steinhardt <ps@pks.im> | 2019-01-23 10:48:55 +0100 |
|---|---|---|
| committer | Patrick Steinhardt <ps@pks.im> | 2019-02-15 13:16:48 +0100 |
| commit | 2e0a304839764236654e73d38fa380b317a3fac1 (patch) | |
| tree | fdba155593c31b1bb6260ad6bb09dba644bb8a56 /src/pack-objects.c | |
| parent | 9694ef2064be3ecc3f173af296ab091f0498234d (diff) | |
| download | libgit2-2e0a304839764236654e73d38fa380b317a3fac1.tar.gz | |
oidmap: introduce high-level setter for key/value pairs
Currently, one would use either `git_oidmap_insert` to insert key/value pairs
into a map or `git_oidmap_put` to insert a key only. These function have
historically been macros, which is why their syntax is kind of weird: instead of
returning an error code directly, they instead have to be passed a pointer to
where the return value shall be stored. This does not match libgit2's common
idiom of directly returning error codes.Furthermore, `git_oidmap_put` is tightly
coupled with implementation details of the map as it exposes the index of
inserted entries.
Introduce a new function `git_oidmap_set`, which takes as parameters the map,
key and value and directly returns an error code. Convert all trivial callers of
`git_oidmap_insert` and `git_oidmap_put` to make use of it.
Diffstat (limited to 'src/pack-objects.c')
| -rw-r--r-- | src/pack-objects.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/pack-objects.c b/src/pack-objects.c index 094317a80..b2e2457d1 100644 --- a/src/pack-objects.c +++ b/src/pack-objects.c @@ -192,24 +192,26 @@ unsigned int git_packbuilder_set_threads(git_packbuilder *pb, unsigned int n) return pb->nr_threads; } -static void rehash(git_packbuilder *pb) +static int rehash(git_packbuilder *pb) { git_pobject *po; - size_t pos, i; - int ret; + size_t i; git_oidmap_clear(pb->object_ix); + for (i = 0, po = pb->object_list; i < pb->nr_objects; i++, po++) { - pos = git_oidmap_put(pb->object_ix, &po->id, &ret); - git_oidmap_set_value_at(pb->object_ix, pos, po); + if (git_oidmap_set(pb->object_ix, &po->id, po) < 0) + return -1; } + + return 0; } int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid, const char *name) { git_pobject *po; - size_t newsize, pos; + size_t newsize; int ret; assert(pb && oid); @@ -233,7 +235,9 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid, pb->object_list = git__reallocarray(pb->object_list, pb->nr_alloc, sizeof(*po)); GIT_ERROR_CHECK_ALLOC(pb->object_list); - rehash(pb); + + if (rehash(pb) < 0) + return -1; } po = pb->object_list + pb->nr_objects; @@ -246,13 +250,10 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid, git_oid_cpy(&po->id, oid); po->hash = name_hash(name); - pos = git_oidmap_put(pb->object_ix, &po->id, &ret); - if (ret < 0) { + if (git_oidmap_set(pb->object_ix, &po->id, po) < 0) { git_error_set_oom(); - return ret; + return -1; } - assert(ret != 0); - git_oidmap_set_value_at(pb->object_ix, pos, po); pb->done = false; @@ -1541,7 +1542,8 @@ static int retrieve_object(struct walk_object **out, git_packbuilder *pb, const if ((error = lookup_walk_object(&obj, pb, id)) < 0) return error; - git_oidmap_insert(pb->walk_objects, &obj->id, obj, &error); + if ((error = git_oidmap_set(pb->walk_objects, &obj->id, obj)) < 0) + return error; } *out = obj; |
