From c9bf04eb66c9bf064331235d964cdd8920b1156a Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Mon, 9 Feb 2015 22:51:55 -0500 Subject: [PATCH] Fix string_map_remove to not use the hashtab INSERT mode --- include/tig/map.h | 2 +- src/map.c | 14 +++++++++++--- src/refdb.c | 6 ++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/tig/map.h b/include/tig/map.h index 28ecfe1..477a8b0 100644 --- a/include/tig/map.h +++ b/include/tig/map.h @@ -37,7 +37,7 @@ extern string_map_hash_fn string_map_hash_helper; void *string_map_get(struct string_map *map, const char *key); void *string_map_put(struct string_map *map, const char *key, void *value); void **string_map_put_to(struct string_map *map, const char *key); -void *string_map_remove(struct string_map *map, void **slot); +void *string_map_remove(struct string_map *map, const char *key); void string_map_clear(struct string_map *map); void string_map_foreach(struct string_map *map, string_map_iterator_fn iterator, void *data); diff --git a/src/map.c b/src/map.c index 24dce00..baa16fc 100644 --- a/src/map.c +++ b/src/map.c @@ -65,12 +65,20 @@ string_map_put(struct string_map *map, const char *key, void *value) } void * -string_map_remove(struct string_map *map, void **slot) +string_map_remove(struct string_map *map, const char *key) { - void *value = slot ? *slot : NULL; + void *value = NULL; + void **slot; - if (map->htab && slot) + if (!map->htab) + return NULL; + + map->key = key; + slot = htab_find_slot_with_hash(map->htab, map, htab_hash_string(key), NO_INSERT); + if (slot) { + value = *slot; htab_clear_slot(map->htab, slot); + } return value; } diff --git a/src/refdb.c b/src/refdb.c index d91bcc2..539f720 100644 --- a/src/refdb.c +++ b/src/refdb.c @@ -149,11 +149,9 @@ add_to_refs(const char *id, size_t idlen, char *name, size_t namelen, struct ref * git-ls-remote lists the commit id of an annotated tag right * before the commit id it points to. */ if (type == REFERENCE_REPLACE) { - ref_slot = string_map_put_to(&refs_by_id, id); - if (!ref_slot) + ref = string_map_remove(&refs_by_id, id); + if (!ref) return ERR; - if (*ref_slot) - ref = string_map_remove(&refs_by_id, ref_slot); } else { ref_slot = string_map_put_to(&refs_by_name, name); -- 2.11.4.GIT