summaryrefslogtreecommitdiff
path: root/src/tree.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2019-01-23 10:44:33 +0100
committerPatrick Steinhardt <ps@pks.im>2019-02-15 13:16:48 +0100
commit03555830784a2856e0c9651d2643b3ee5ce2084d (patch)
tree9796bff7a6ea1a3035565645ab41c49b32d457c8 /src/tree.c
parentef507bc7bdd736d2379a0d0614b3db1341d77187 (diff)
downloadlibgit2-03555830784a2856e0c9651d2643b3ee5ce2084d.tar.gz
strmap: introduce high-level setter for key/value pairs
Currently, one would use the function `git_strmap_insert` to insert key/value pairs into a map. This function has historically been a macro, which is why its syntax is kind of weird: instead of returning an error code directly, it instead has 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. Introduce a new function `git_strmap_set`, which takes as parameters the map, key and value and directly returns an error code. Convert all callers of `git_strmap_insert` to make use of it.
Diffstat (limited to 'src/tree.c')
-rw-r--r--src/tree.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/src/tree.c b/src/tree.c
index b1665cee3..12317540c 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -507,8 +507,7 @@ static int append_entry(
entry->attr = (uint16_t)filemode;
- git_strmap_insert(bld->map, entry->filename, entry, &error);
- if (error < 0) {
+ if ((error = git_strmap_set(bld->map, entry->filename, entry)) < 0) {
git_tree_entry_free(entry);
git_error_set(GIT_ERROR_TREE, "failed to append entry %s to the tree builder", filename);
return -1;
@@ -735,9 +734,7 @@ int git_treebuilder_insert(
entry = alloc_entry(filename, strlen(filename), id);
GIT_ERROR_CHECK_ALLOC(entry);
- git_strmap_insert(bld->map, entry->filename, entry, &error);
-
- if (error < 0) {
+ if ((error = git_strmap_set(bld->map, entry->filename, entry)) < 0) {
git_tree_entry_free(entry);
git_error_set(GIT_ERROR_TREE, "failed to insert %s", filename);
return -1;