@@ -263,11 +263,13 @@ static int note_tree_consolidate(struct int_node *tree,
263263 * To remove a leaf_node:
264264 * Search to the tree location appropriate for the given leaf_node's key:
265265 * - If location does not hold a matching entry, abort and do nothing.
266+ * - Copy the matching entry's value into the given entry.
266267 * - Replace the matching leaf_node with a NULL entry (and free the leaf_node).
267268 * - Consolidate int_nodes repeatedly, while walking up the tree towards root.
268269 */
269- static void note_tree_remove (struct notes_tree * t , struct int_node * tree ,
270- unsigned char n , struct leaf_node * entry )
270+ static void note_tree_remove (struct notes_tree * t ,
271+ struct int_node * tree , unsigned char n ,
272+ struct leaf_node * entry )
271273{
272274 struct leaf_node * l ;
273275 struct int_node * parent_stack [20 ];
@@ -282,6 +284,7 @@ static void note_tree_remove(struct notes_tree *t, struct int_node *tree,
282284 return ; /* key mismatch, nothing to remove */
283285
284286 /* we have found a matching entry */
287+ hashcpy (entry -> val_sha1 , l -> val_sha1 );
285288 free (l );
286289 * p = SET_PTR_TYPE (NULL , PTR_TYPE_NULL );
287290
@@ -1003,17 +1006,20 @@ void add_note(struct notes_tree *t, const unsigned char *object_sha1,
10031006 note_tree_insert (t , t -> root , 0 , l , PTR_TYPE_NOTE , combine_notes );
10041007}
10051008
1006- void remove_note (struct notes_tree * t , const unsigned char * object_sha1 )
1009+ int remove_note (struct notes_tree * t , const unsigned char * object_sha1 )
10071010{
10081011 struct leaf_node l ;
10091012
10101013 if (!t )
10111014 t = & default_notes_tree ;
10121015 assert (t -> initialized );
1013- t -> dirty = 1 ;
10141016 hashcpy (l .key_sha1 , object_sha1 );
10151017 hashclr (l .val_sha1 );
10161018 note_tree_remove (t , t -> root , 0 , & l );
1019+ if (is_null_sha1 (l .val_sha1 )) // no note was removed
1020+ return 1 ;
1021+ t -> dirty = 1 ;
1022+ return 0 ;
10171023}
10181024
10191025const unsigned char * get_note (struct notes_tree * t ,
0 commit comments