235
* - Else, create a new int_node, holding both the node-at-location and the
236
* node-to-be-inserted, and store the new int_node into the location.
237
*/
238
-static void note_tree_insert(struct notes_tree *t, struct int_node *tree,
238
+static int note_tree_insert(struct notes_tree *t, struct int_node *tree,
239
unsigned char n, struct leaf_node *entry, unsigned char type,
240
combine_notes_fn combine_notes)
241
{
242
struct int_node *new_node;
243
struct leaf_node *l;
244
void **p = note_tree_search(t, &tree, &n, entry->key_sha1);
245
+ int ret = 0;
246
247
assert(GET_PTR_TYPE(entry) == 0); /* no type bits set */
248
l = (struct leaf_node *) CLR_PTR_TYPE(*p);
253
free(entry);
254
else
255
*p = SET_PTR_TYPE(entry, type);
255
- return;
256
+ return 0;
257
case PTR_TYPE_NOTE:
258
switch (type) {
259
case PTR_TYPE_NOTE:
260
if (!hashcmp(l->key_sha1, entry->key_sha1)) {
261
/* skip concatenation if l == entry */
262
if (!hashcmp(l->val_sha1, entry->val_sha1))
262
- return;
263
+ return 0;
264
264
- if (combine_notes(l->val_sha1, entry->val_sha1))
265
- die("failed to combine notes %s and %s"
266
- " for object %s",
267
- sha1_to_hex(l->val_sha1),
268
- sha1_to_hex(entry->val_sha1),
269
- sha1_to_hex(l->key_sha1));
270
-
271
- if (is_null_sha1(l->val_sha1))
265
+ ret = combine_notes(l->val_sha1,
266
+ entry->val_sha1);
267
+ if (!ret && is_null_sha1(l->val_sha1))
268
note_tree_remove(t, tree, n, entry);
269
free(entry);
274
- return;
270
+ return ret;
271
}
272
break;
273
case PTR_TYPE_SUBTREE:
276
/* unpack 'entry' */
277
load_subtree(t, entry, tree, n);
278
free(entry);
283
- return;
279
+ return 0;
280
}
281
break;
282
}
287
*p = NULL;
288
load_subtree(t, l, tree, n);
289
free(l);
294
- note_tree_insert(t, tree, n, entry, type,
295
- combine_notes);
296
- return;
290
+ return note_tree_insert(t, tree, n, entry, type,
291
+ combine_notes);
292
}
293
break;
294
}
298
GET_PTR_TYPE(*p) == PTR_TYPE_SUBTREE);
299
if (is_null_sha1(entry->val_sha1)) { /* skip insertion of empty note */
300
free(entry);
306
- return;
301
+ return 0;
302
}
303
new_node = (struct int_node *) xcalloc(sizeof(struct int_node), 1);
309
- note_tree_insert(t, new_node, n + 1, l, GET_PTR_TYPE(*p),
310
- combine_notes);
304
+ ret = note_tree_insert(t, new_node, n + 1, l, GET_PTR_TYPE(*p),
305
+ combine_notes);
306
+ if (ret)
307
+ return ret;
308
*p = SET_PTR_TYPE(new_node, PTR_TYPE_INTERNAL);
312
- note_tree_insert(t, new_node, n + 1, entry, type, combine_notes);
309
+ return note_tree_insert(t, new_node, n + 1, entry, type, combine_notes);
310
}
311
312
/* Free the entire notes data contained in the given tree */
449
l->key_sha1[19] = (unsigned char) len;
450
type = PTR_TYPE_SUBTREE;
451
}
455
- note_tree_insert(t, node, n, l, type,
456
- combine_notes_concatenate);
452
+ if (note_tree_insert(t, node, n, l, type,
453
+ combine_notes_concatenate))
454
+ die("Failed to load %s %s into notes tree "
455
+ "from %s",
456
+ type == PTR_TYPE_NOTE ? "note" : "subtree",
457
+ sha1_to_hex(l->key_sha1), t->ref);
458
}
459
continue;
460
1015
string_list_clear(&display_notes_refs, 0);
1016
}
1017
1017
-void add_note(struct notes_tree *t, const unsigned char *object_sha1,
1018
+int add_note(struct notes_tree *t, const unsigned char *object_sha1,
1019
const unsigned char *note_sha1, combine_notes_fn combine_notes)
1020
{
1021
struct leaf_node *l;
1029
l = (struct leaf_node *) xmalloc(sizeof(struct leaf_node));
1030
hashcpy(l->key_sha1, object_sha1);
1031
hashcpy(l->val_sha1, note_sha1);
1031
- note_tree_insert(t, t->root, 0, l, PTR_TYPE_NOTE, combine_notes);
1032
+ return note_tree_insert(t, t->root, 0, l, PTR_TYPE_NOTE, combine_notes);
1033
}
1034
1035
void remove_note(struct notes_tree *t, const unsigned char *object_sha1)
1205
1206
int copy_note(struct notes_tree *t,
1207
const unsigned char *from_obj, const unsigned char *to_obj,
1207
- int force, combine_notes_fn combine_fn)
1208
+ int force, combine_notes_fn combine_notes)
1209
{
1210
const unsigned char *note = get_note(t, from_obj);
1211
const unsigned char *existing_note = get_note(t, to_obj);
1214
return 1;
1215
1216
if (note)
1216
- add_note(t, to_obj, note, combine_fn);
1217
+ return add_note(t, to_obj, note, combine_notes);
1218
else if (existing_note)
1218
- add_note(t, to_obj, null_sha1, combine_fn);
1219
+ return add_note(t, to_obj, null_sha1, combine_notes);
1220
1221
return 0;
1222
}