diff options
| author | Patrick Steinhardt <ps@pks.im> | 2018-12-01 08:50:36 +0100 |
|---|---|---|
| committer | Patrick Steinhardt <ps@pks.im> | 2019-02-15 13:16:48 +0100 |
| commit | 84a089da3701db370b2c77e6866abe3a5065c542 (patch) | |
| tree | a70b47efb1c29ab0c779fbb7f25447a33d9d0dce /src/idxmap.c | |
| parent | 8da93944f3d3c271ea7a2ec035c6ea48654fa71e (diff) | |
| download | libgit2-84a089da3701db370b2c77e6866abe3a5065c542.tar.gz | |
maps: provide return value when deleting entries
Currently, the delete functions of maps do not provide a return value. Like
this, it is impossible to tell whether the entry has really been deleted or not.
Change the implementation to provide either a return value of zero if the entry
has been successfully deleted or `GIT_ENOTFOUND` if the key could not be found.
Convert callers to the `delete_at` functions to instead use this higher-level
interface.
Diffstat (limited to 'src/idxmap.c')
| -rw-r--r-- | src/idxmap.c | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/idxmap.c b/src/idxmap.c index e3fcfb82c..d7aa4ea6b 100644 --- a/src/idxmap.c +++ b/src/idxmap.c @@ -160,6 +160,24 @@ void git_idxmap_icase_insert(git_idxmap_icase *map, const git_index_entry *key, } } +int git_idxmap_delete(git_idxmap *map, const git_index_entry *key) +{ + khiter_t idx = git_idxmap_lookup_index(map, key); + if (!git_idxmap_valid_index(map, idx)) + return GIT_ENOTFOUND; + git_idxmap_delete_at(map, idx); + return 0; +} + +int git_idxmap_icase_delete(git_idxmap_icase *map, const git_index_entry *key) +{ + khiter_t idx = git_idxmap_icase_lookup_index(map, key); + if (!git_idxmap_valid_index((git_idxmap *)map, idx)) + return GIT_ENOTFOUND; + git_idxmap_icase_delete_at(map, idx); + return 0; +} + size_t git_idxmap_lookup_index(git_idxmap *map, const git_index_entry *key) { return kh_get(idx, map, key); @@ -204,16 +222,3 @@ void git_idxmap_icase_delete_at(git_idxmap_icase *map, size_t idx) { kh_del(idxicase, map, idx); } - -void git_idxmap_delete(git_idxmap *map, const git_index_entry *key) -{ - khiter_t idx = git_idxmap_lookup_index(map, key); - if (git_idxmap_valid_index(map, idx)) - git_idxmap_delete_at(map, idx); -} -void git_idxmap_icase_delete(git_idxmap_icase *map, const git_index_entry *key) -{ - khiter_t idx = git_idxmap_icase_lookup_index(map, key); - if (git_idxmap_valid_index((git_idxmap *)map, idx)) - git_idxmap_icase_delete_at(map, idx); -} |
