MCPcopy Index your code
hub / github.com/git/git / note_tree_remove

Function note_tree_remove

notes.c:202–238  ·  view source on GitHub ↗

* To remove a leaf_node: * Search to the tree location appropriate for the given leaf_node's key: * - If location does not hold a matching entry, abort and do nothing. * - Copy the matching entry's value into the given entry. * - Replace the matching leaf_node with a NULL entry (and free the leaf_node). * - Consolidate int_nodes repeatedly, while walking up the tree towards root. */

Source from the content-addressed store, hash-verified

200 * - Consolidate int_nodes repeatedly, while walking up the tree towards root.
201 */
202static void note_tree_remove(struct notes_tree *t,
203 struct int_node *tree, unsigned char n,
204 struct leaf_node *entry)
205{
206 struct leaf_node *l;
207 struct int_node *parent_stack[GIT_MAX_RAWSZ];
208 unsigned char i, j;
209 void **p = note_tree_search(t, &tree, &n, entry->key_oid.hash);
210
211 assert(GET_PTR_TYPE(entry) == 0); /* no type bits set */
212 if (GET_PTR_TYPE(*p) != PTR_TYPE_NOTE)
213 return; /* type mismatch, nothing to remove */
214 l = (struct leaf_node *) CLR_PTR_TYPE(*p);
215 if (!oideq(&l->key_oid, &entry->key_oid))
216 return; /* key mismatch, nothing to remove */
217
218 /* we have found a matching entry */
219 oidcpy(&entry->val_oid, &l->val_oid);
220 free(l);
221 *p = SET_PTR_TYPE(NULL, PTR_TYPE_NULL);
222
223 /* consolidate this tree level, and parent levels, if possible */
224 if (!n)
225 return; /* cannot consolidate top level */
226 /* first, build stack of ancestors between root and current node */
227 parent_stack[0] = t->root;
228 for (i = 0; i < n; i++) {
229 j = GET_NIBBLE(i, entry->key_oid.hash);
230 parent_stack[i + 1] = CLR_PTR_TYPE(parent_stack[i]->a[j]);
231 }
232 assert(i == n && parent_stack[i] == tree);
233 /* next, unwind stack until note_tree_consolidate() is done */
234 while (i > 0 &&
235 !note_tree_consolidate(parent_stack[i], parent_stack[i - 1],
236 GET_NIBBLE(i - 1, entry->key_oid.hash)))
237 i--;
238}
239
240/*
241 * To insert a leaf_node:

Callers 2

note_tree_insertFunction · 0.85
remove_noteFunction · 0.85

Calls 4

note_tree_searchFunction · 0.85
oideqFunction · 0.85
oidcpyFunction · 0.85
note_tree_consolidateFunction · 0.85

Tested by

no test coverage detected