Skip to content

Commit 91f6922

Browse files
committed
Merge branch 'sb/hashmap-customize-comparison'
Update the hashmap API so that data to customize the behaviour of the comparison function can be specified at the time a hashmap is initialized. * sb/hashmap-customize-comparison: hashmap: migrate documentation from Documentation/technical into header patch-ids.c: use hashmap correctly hashmap.h: compare function has access to a data field
2 parents eac97b4 + 1ecbf31 commit 91f6922

20 files changed

+431
-409
lines changed

Documentation/technical/api-hashmap.txt

Lines changed: 0 additions & 309 deletions
This file was deleted.

attr.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,18 @@ struct attr_hash_entry {
7676
};
7777

7878
/* attr_hashmap comparison function */
79-
static int attr_hash_entry_cmp(const struct attr_hash_entry *a,
79+
static int attr_hash_entry_cmp(void *unused_cmp_data,
80+
const struct attr_hash_entry *a,
8081
const struct attr_hash_entry *b,
81-
void *unused)
82+
void *unused_keydata)
8283
{
8384
return (a->keylen != b->keylen) || strncmp(a->key, b->key, a->keylen);
8485
}
8586

8687
/* Initialize an 'attr_hashmap' object */
8788
static void attr_hashmap_init(struct attr_hashmap *map)
8889
{
89-
hashmap_init(&map->map, (hashmap_cmp_fn) attr_hash_entry_cmp, 0);
90+
hashmap_init(&map->map, (hashmap_cmp_fn) attr_hash_entry_cmp, NULL, 0);
9091
}
9192

9293
/*

builtin/describe.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ static const char *prio_names[] = {
5454
N_("head"), N_("lightweight"), N_("annotated"),
5555
};
5656

57-
static int commit_name_cmp(const struct commit_name *cn1,
58-
const struct commit_name *cn2, const void *peeled)
57+
static int commit_name_cmp(const void *unused_cmp_data,
58+
const struct commit_name *cn1,
59+
const struct commit_name *cn2,
60+
const void *peeled)
5961
{
6062
return oidcmp(&cn1->peeled, peeled ? peeled : &cn2->peeled);
6163
}
@@ -501,7 +503,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
501503
return cmd_name_rev(args.argc, args.argv, prefix);
502504
}
503505

504-
hashmap_init(&names, (hashmap_cmp_fn) commit_name_cmp, 0);
506+
hashmap_init(&names, (hashmap_cmp_fn) commit_name_cmp, NULL, 0);
505507
for_each_rawref(get_name, NULL);
506508
if (!names.size && !always)
507509
die(_("No names found, cannot describe anything."));

0 commit comments

Comments
 (0)