mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
reftable/tree: handle allocation failures
The tree interfaces of the reftable library handle both insertion and searching of tree nodes with a single function, where the behaviour is altered between the two via an `insert` bit. This makes it quit awkward to handle allocation failures because on inserting we'd have to check for `NULL` pointers and return an error, whereas on searching entries we don't have to handle it as an allocation error. Split up concerns of this function into two separate functions, one for inserting entries and one for searching entries. This makes it easy for us to check for allocation errors as `tree_insert()` should never return a `NULL` pointer now. Adapt callers accordingly. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
d0501c8c9d
commit
51afc709dc
@@ -208,8 +208,7 @@ static int writer_index_hash(struct reftable_writer *w, struct strbuf *hash)
|
||||
struct obj_index_tree_node *key;
|
||||
struct tree_node *node;
|
||||
|
||||
node = tree_search(&want, &w->obj_index_tree,
|
||||
&obj_index_tree_node_compare, 0);
|
||||
node = tree_search(w->obj_index_tree, &want, &obj_index_tree_node_compare);
|
||||
if (!node) {
|
||||
struct obj_index_tree_node empty = OBJ_INDEX_TREE_NODE_INIT;
|
||||
|
||||
@@ -221,8 +220,8 @@ static int writer_index_hash(struct reftable_writer *w, struct strbuf *hash)
|
||||
|
||||
strbuf_reset(&key->hash);
|
||||
strbuf_addbuf(&key->hash, hash);
|
||||
tree_search((void *)key, &w->obj_index_tree,
|
||||
&obj_index_tree_node_compare, 1);
|
||||
tree_insert(&w->obj_index_tree, key,
|
||||
&obj_index_tree_node_compare);
|
||||
} else {
|
||||
key = node->key;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user