Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Beller <sbeller@google.com>2017-06-30 22:14:05 +0300
committerJunio C Hamano <gitster@pobox.com>2017-06-30 22:49:28 +0300
commit7663cdc86c860d5b5293a1dd4b0fb6c4e006d08e (patch)
tree19a347bfc7b3eb59f2f30c581c8408679001d764 /name-hash.c
parente0aaa1b6532cfce93d87af9bc813fb2e7a7ce9d7 (diff)
hashmap.h: compare function has access to a data field
When using the hashmap a common need is to have access to caller provided data in the compare function. A couple of times we abuse the keydata field to pass in the data needed. This happens for example in patch-ids.c. This patch changes the function signature of the compare function to have one more void pointer available. The pointer given for each invocation of the compare function must be defined in the init function of the hashmap and is just passed through. Documentation of this new feature is deferred to a later patch. This is a rather mechanical conversion, just adding the new pass-through parameter. However while at it improve the naming of the fields of all compare functions used by hashmaps by ensuring unused parameters are prefixed with 'unused_' and naming the parameters what they are (instead of 'unused' make it 'unused_keydata'). Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'name-hash.c')
-rw-r--r--name-hash.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/name-hash.c b/name-hash.c
index 39309efb7f..0e10f3eab8 100644
--- a/name-hash.c
+++ b/name-hash.c
@@ -16,8 +16,10 @@ struct dir_entry {
char name[FLEX_ARRAY];
};
-static int dir_entry_cmp(const struct dir_entry *e1,
- const struct dir_entry *e2, const char *name)
+static int dir_entry_cmp(const void *unused_cmp_data,
+ const struct dir_entry *e1,
+ const struct dir_entry *e2,
+ const char *name)
{
return e1->namelen != e2->namelen || strncasecmp(e1->name,
name ? name : e2->name, e1->namelen);
@@ -107,8 +109,10 @@ static void hash_index_entry(struct index_state *istate, struct cache_entry *ce)
add_dir_entry(istate, ce);
}
-static int cache_entry_cmp(const struct cache_entry *ce1,
- const struct cache_entry *ce2, const void *remove)
+static int cache_entry_cmp(const void *unused_cmp_data,
+ const struct cache_entry *ce1,
+ const struct cache_entry *ce2,
+ const void *remove)
{
/*
* For remove_name_hash, find the exact entry (pointer equality); for
@@ -571,9 +575,9 @@ static void lazy_init_name_hash(struct index_state *istate)
if (istate->name_hash_initialized)
return;
hashmap_init(&istate->name_hash, (hashmap_cmp_fn) cache_entry_cmp,
- istate->cache_nr);
+ NULL, istate->cache_nr);
hashmap_init(&istate->dir_hash, (hashmap_cmp_fn) dir_entry_cmp,
- istate->cache_nr);
+ NULL, istate->cache_nr);
if (lookup_lazy_params(istate)) {
hashmap_disallow_rehash(&istate->dir_hash, 1);