summaryrefslogtreecommitdiff
path: root/src/oidmap.h
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2019-01-23 10:48:55 +0100
committerPatrick Steinhardt <ps@pks.im>2019-02-15 13:16:48 +0100
commit2e0a304839764236654e73d38fa380b317a3fac1 (patch)
treefdba155593c31b1bb6260ad6bb09dba644bb8a56 /src/oidmap.h
parent9694ef2064be3ecc3f173af296ab091f0498234d (diff)
downloadlibgit2-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/oidmap.h')
-rw-r--r--src/oidmap.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/oidmap.h b/src/oidmap.h
index 799fec402..39987d336 100644
--- a/src/oidmap.h
+++ b/src/oidmap.h
@@ -61,6 +61,21 @@ size_t git_oidmap_size(git_oidmap *map);
*/
void *git_oidmap_get(git_oidmap *map, const git_oid *key);
+/**
+ * Set the entry for key to value.
+ *
+ * If the map has no corresponding entry for the given key, a new
+ * entry will be created with the given value. If an entry exists
+ * already, its value will be updated to match the given value.
+ *
+ * @param map map to create new entry in
+ * @param key key to set
+ * @param value value to associate the key with; may be NULL
+ * @return zero if the key was successfully set, a negative error
+ * code otherwise
+ */
+int git_oidmap_set(git_oidmap *map, const git_oid *key, void *value);
+
size_t git_oidmap_lookup_index(git_oidmap *map, const git_oid *key);
int git_oidmap_valid_index(git_oidmap *map, size_t idx);