#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
+#include "config.h"
#include "exec_cmd.h"
#include "attr.h"
#include "dir.h"
};
/* attr_hashmap comparison function */
-static int attr_hash_entry_cmp(const struct attr_hash_entry *a,
- const struct attr_hash_entry *b,
- void *unused)
+static int attr_hash_entry_cmp(const void *unused_cmp_data,
+ const void *entry,
+ const void *entry_or_key,
+ const void *unused_keydata)
{
+ const struct attr_hash_entry *a = entry;
+ const struct attr_hash_entry *b = entry_or_key;
return (a->keylen != b->keylen) || strncmp(a->key, b->key, a->keylen);
}
/* Initialize an 'attr_hashmap' object */
static void attr_hashmap_init(struct attr_hashmap *map)
{
- hashmap_init(&map->map, (hashmap_cmp_fn) attr_hash_entry_cmp, 0);
+ hashmap_init(&map->map, attr_hash_entry_cmp, NULL, 0);
}
/*
static void all_attrs_init(struct attr_hashmap *map, struct attr_check *check)
{
int i;
+ unsigned int size;
hashmap_lock(map);
- if (map->map.size < check->all_attrs_nr)
+ size = hashmap_get_size(&map->map);
+ if (size < check->all_attrs_nr)
die("BUG: interned attributes shouldn't be deleted");
/*
* field), reallocate the provided attr_check instance's all_attrs
* field and fill each entry with its corresponding git_attr.
*/
- if (map->map.size != check->all_attrs_nr) {
+ if (size != check->all_attrs_nr) {
struct attr_hash_entry *e;
struct hashmap_iter iter;
hashmap_iter_init(&map->map, &iter);
- REALLOC_ARRAY(check->all_attrs, map->map.size);
- check->all_attrs_nr = map->map.size;
+ REALLOC_ARRAY(check->all_attrs, size);
+ check->all_attrs_nr = size;
while ((e = hashmap_iter_next(&iter))) {
const struct git_attr *a = e->value;
if (!a) {
FLEX_ALLOC_MEM(a, name, name, namelen);
- a->attr_nr = g_attr_hashmap.map.size;
+ a->attr_nr = hashmap_get_size(&g_attr_hashmap.map);
attr_hashmap_add(&g_attr_hashmap, a->name, namelen, a);
- assert(a->attr_nr == (g_attr_hashmap.map.size - 1));
+ assert(a->attr_nr ==
+ (hashmap_get_size(&g_attr_hashmap.map) - 1));
}
hashmap_unlock(&g_attr_hashmap);
void attr_check_clear(struct attr_check *check)
{
- free(check->items);
- check->items = NULL;
+ FREE_AND_NULL(check->items);
check->alloc = 0;
check->nr = 0;
- free(check->all_attrs);
- check->all_attrs = NULL;
+ FREE_AND_NULL(check->all_attrs);
check->all_attrs_nr = 0;
drop_attr_stack(&check->stack);