From: Junio C Hamano Date: Fri, 11 Aug 2017 20:27:01 +0000 (-0700) Subject: Merge branch 'sb/hashmap-cleanup' X-Git-Tag: v2.15.0-rc0~198 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=55c965f3a27b3a36f84c56b6eba8ac5c95ff558a;p=thirdparty%2Fgit.git Merge branch 'sb/hashmap-cleanup' Many uses of comparision callback function the hashmap API uses cast the callback function type when registering it to hashmap_init(), which defeats the compile time type checking when the callback interface changes (e.g. gaining more parameters). The callback implementations have been updated to take "void *" pointers and cast them to the type they expect instead. * sb/hashmap-cleanup: t/helper/test-hashmap: use custom data instead of duplicate cmp functions name-hash.c: drop hashmap_cmp_fn cast submodule-config.c: drop hashmap_cmp_fn cast remote.c: drop hashmap_cmp_fn cast patch-ids.c: drop hashmap_cmp_fn cast convert/sub-process: drop cast to hashmap_cmp_fn config.c: drop hashmap_cmp_fn cast builtin/describe: drop hashmap_cmp_fn cast builtin/difftool.c: drop hashmap_cmp_fn cast attr.c: drop hashmap_cmp_fn cast --- 55c965f3a27b3a36f84c56b6eba8ac5c95ff558a diff --cc submodule-config.c index d48403f25e,edc8dd04b6..bede338c85 --- a/submodule-config.c +++ b/submodule-config.c @@@ -34,11 -31,17 +34,14 @@@ enum lookup_type lookup_path }; -static struct submodule_cache the_submodule_cache; -static int is_cache_init; - static int config_path_cmp(const void *unused_cmp_data, - const struct submodule_entry *a, - const struct submodule_entry *b, + const void *entry, + const void *entry_or_key, const void *unused_keydata) { + const struct submodule_entry *a = entry; + const struct submodule_entry *b = entry_or_key; + return strcmp(a->config->path, b->config->path) || hashcmp(a->config->gitmodules_sha1, b->config->gitmodules_sha1); } @@@ -52,16 -58,10 +58,16 @@@ static int config_name_cmp(const void * hashcmp(a->config->gitmodules_sha1, b->config->gitmodules_sha1); } -static void cache_init(struct submodule_cache *cache) +static struct submodule_cache *submodule_cache_alloc(void) +{ + return xcalloc(1, sizeof(struct submodule_cache)); +} + +static void submodule_cache_init(struct submodule_cache *cache) { - hashmap_init(&cache->for_path, (hashmap_cmp_fn) config_path_cmp, NULL, 0); - hashmap_init(&cache->for_name, (hashmap_cmp_fn) config_name_cmp, NULL, 0); + hashmap_init(&cache->for_path, config_path_cmp, NULL, 0); + hashmap_init(&cache->for_name, config_name_cmp, NULL, 0); + cache->initialized = 1; } static void free_one_config(struct submodule_entry *entry)