MCPcopy Create free account
hub / github.com/git/git / all_attrs_init

Function all_attrs_init

attr.c:146–188  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

144 * of attributes.
145 */
146static void all_attrs_init(struct attr_hashmap *map, struct attr_check *check)
147{
148 int i;
149 unsigned int size;
150
151 hashmap_lock(map);
152
153 size = hashmap_get_size(&map->map);
154 if (size < check->all_attrs_nr)
155 BUG("interned attributes shouldn't be deleted");
156
157 /*
158 * If the number of attributes in the global dictionary has increased
159 * (or this attr_check instance doesn't have an initialized all_attrs
160 * field), reallocate the provided attr_check instance's all_attrs
161 * field and fill each entry with its corresponding git_attr.
162 */
163 if (size != check->all_attrs_nr) {
164 struct attr_hash_entry *e;
165 struct hashmap_iter iter;
166
167 REALLOC_ARRAY(check->all_attrs, size);
168 check->all_attrs_nr = size;
169
170 hashmap_for_each_entry(&map->map, &iter, e,
171 ent /* member name */) {
172 const struct git_attr *a = e->value;
173 check->all_attrs[a->attr_nr].attr = a;
174 }
175 }
176
177 hashmap_unlock(map);
178
179 /*
180 * Re-initialize every entry in check->all_attrs.
181 * This re-initialization can live outside of the locked region since
182 * the attribute dictionary is no longer being accessed.
183 */
184 for (i = 0; i < check->all_attrs_nr; i++) {
185 check->all_attrs[i].value = ATTR__UNKNOWN;
186 check->all_attrs[i].macro = NULL;
187 }
188}
189
190/*
191 * Attribute name cannot begin with "builtin_" which

Callers 1

collect_some_attrsFunction · 0.85

Calls 3

hashmap_lockFunction · 0.85
hashmap_get_sizeFunction · 0.85
hashmap_unlockFunction · 0.85

Tested by

no test coverage detected