diff options
author | Patrick Steinhardt <ps@pks.im> | 2019-01-23 10:44:33 +0100 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2019-02-15 13:16:48 +0100 |
commit | 03555830784a2856e0c9651d2643b3ee5ce2084d (patch) | |
tree | 9796bff7a6ea1a3035565645ab41c49b32d457c8 /src/attrcache.c | |
parent | ef507bc7bdd736d2379a0d0614b3db1341d77187 (diff) | |
download | libgit2-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/attrcache.c')
-rw-r--r-- | src/attrcache.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/attrcache.c b/src/attrcache.c index f1bc0df5f..00e45966c 100644 --- a/src/attrcache.c +++ b/src/attrcache.c @@ -75,18 +75,16 @@ int git_attr_cache__alloc_file_entry( static int attr_cache_make_entry( git_attr_file_entry **out, git_repository *repo, const char *path) { - int error = 0; git_attr_cache *cache = git_repository_attr_cache(repo); git_attr_file_entry *entry = NULL; + int error; - error = git_attr_cache__alloc_file_entry( - &entry, git_repository_workdir(repo), path, &cache->pool); + if ((error = git_attr_cache__alloc_file_entry(&entry, git_repository_workdir(repo), + path, &cache->pool)) < 0) + return error; - if (!error) { - git_strmap_insert(cache->files, entry->path, entry, &error); - if (error > 0) - error = 0; - } + if ((error = git_strmap_set(cache->files, entry->path, entry)) < 0) + return error; *out = entry; return error; @@ -437,11 +435,11 @@ int git_attr_cache__insert_macro(git_repository *repo, git_attr_rule *macro) git_error_set(GIT_ERROR_OS, "unable to get attr cache lock"); error = -1; } else { - git_strmap_insert(macros, macro->match.pattern, macro, &error); + error = git_strmap_set(macros, macro->match.pattern, macro); git_mutex_unlock(&cache->lock); } - return (error < 0) ? -1 : 0; + return error; } git_attr_rule *git_attr_cache__lookup_macro( |