/* * Reallocate and reinitialize the array of all attributes (which is used in * the attribute collection process) in 'check' based on the global dictionary * of attributes. */ static void all_attrs_init(struct attr_hashmap *map, struct attr_check *check) { int i; unsigned int size; hashmap_lock(map); size = hashmap_get_size(&map->map); if (size < check->all_attrs_nr) BUG("interned attributes shouldn't be deleted"); /* * If the number of attributes in the global dictionary has increased * (or this attr_check instance doesn't have an initialized all_attrs * field), reallocate the provided attr_check instance's all_attrs * field and fill each entry with its corresponding git_attr. */ 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, size); check->all_attrs_nr = size; while ((e = hashmap_iter_next(&iter))) { const struct git_attr *a = e->value; check->all_attrs[a->attr_nr].attr = a; } } hashmap_unlock(map); /* * Re-initialize every entry in check->all_attrs. * This re-initialization can live outside of the locked region since * the attribute dictionary is no longer being accessed. */ for (i = 0; i < check->all_attrs_nr; i++) { check->all_attrs[i].value = ATTR__UNKNOWN; check->all_attrs[i].macro = NULL; } }
/* * Given a 'name', lookup and return the corresponding attribute in the global * dictionary. If no entry is found, create a new attribute and store it in * the dictionary. */ static const struct git_attr *git_attr_internal(const char *name, int namelen) { struct git_attr *a; if (!attr_name_valid(name, namelen)) return NULL; hashmap_lock(&g_attr_hashmap); a = attr_hashmap_get(&g_attr_hashmap, name, namelen); if (!a) { FLEX_ALLOC_MEM(a, name, name, namelen); a->attr_nr = g_attr_hashmap.map.size; attr_hashmap_add(&g_attr_hashmap, a->name, namelen, a); assert(a->attr_nr == (g_attr_hashmap.map.size - 1)); } hashmap_unlock(&g_attr_hashmap); return a; }