* 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. */
| 231 | * the dictionary. |
| 232 | */ |
| 233 | static const struct git_attr *git_attr_internal(const char *name, size_t namelen) |
| 234 | { |
| 235 | struct git_attr *a; |
| 236 | |
| 237 | if (!attr_name_valid(name, namelen)) |
| 238 | return NULL; |
| 239 | |
| 240 | hashmap_lock(&g_attr_hashmap); |
| 241 | |
| 242 | a = attr_hashmap_get(&g_attr_hashmap, name, namelen); |
| 243 | |
| 244 | if (!a) { |
| 245 | FLEX_ALLOC_MEM(a, name, name, namelen); |
| 246 | a->attr_nr = hashmap_get_size(&g_attr_hashmap.map); |
| 247 | |
| 248 | attr_hashmap_add(&g_attr_hashmap, a->name, namelen, a); |
| 249 | if (a->attr_nr != hashmap_get_size(&g_attr_hashmap.map) - 1) |
| 250 | die(_("unable to add additional attribute")); |
| 251 | } |
| 252 | |
| 253 | hashmap_unlock(&g_attr_hashmap); |
| 254 | |
| 255 | return a; |
| 256 | } |
| 257 | |
| 258 | const struct git_attr *git_attr(const char *name) |
| 259 | { |
no test coverage detected