summaryrefslogtreecommitdiff
path: root/src/diff_driver.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/diff_driver.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/diff_driver.c')
-rw-r--r--src/diff_driver.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/diff_driver.c b/src/diff_driver.c
index 342ac247a..959cf6258 100644
--- a/src/diff_driver.c
+++ b/src/diff_driver.c
@@ -183,9 +183,9 @@ static int git_diff_driver_builtin(
git_diff_driver_registry *reg,
const char *driver_name)
{
- int error = 0;
git_diff_driver_definition *ddef = NULL;
git_diff_driver *drv = NULL;
+ int error = 0;
size_t idx;
for (idx = 0; idx < ARRAY_SIZE(builtin_defs); ++idx) {
@@ -215,9 +215,8 @@ static int git_diff_driver_builtin(
goto done;
}
- git_strmap_insert(reg->drivers, drv->name, drv, &error);
- if (error > 0)
- error = 0;
+ if ((error = git_strmap_set(reg->drivers, drv->name, drv)) < 0)
+ goto done;
done:
if (error && drv)
@@ -327,10 +326,8 @@ static int git_diff_driver_load(
goto done;
/* store driver in registry */
- git_strmap_insert(reg->drivers, drv->name, drv, &error);
- if (error < 0)
+ if ((error = git_strmap_set(reg->drivers, drv->name, drv)) < 0)
goto done;
- error = 0;
*out = drv;