Allow the test suite to pass in a directory whose name contains spaces
[gitweb.git] / notes.c
diff --git a/notes.c b/notes.c
index df4660fe62ae64356950ca51c1acead0398f93f1..542563b280ad305da1452d57653728b9005874e6 100644 (file)
--- a/notes.c
+++ b/notes.c
@@ -153,8 +153,8 @@ static struct leaf_node *note_tree_find(struct notes_tree *t,
  * How to consolidate an int_node:
  * If there are > 1 non-NULL entries, give up and return non-zero.
  * Otherwise replace the int_node at the given index in the given parent node
- * with the only entry (or a NULL entry if no entries) from the given tree,
- * and return 0.
+ * with the only NOTE entry (or a NULL entry if no entries) from the given
+ * tree, and return 0.
  */
 static int note_tree_consolidate(struct int_node *tree,
        struct int_node *parent, unsigned char index)
@@ -173,6 +173,8 @@ static int note_tree_consolidate(struct int_node *tree,
                }
        }
 
+       if (p && (GET_PTR_TYPE(p) != PTR_TYPE_NOTE))
+               return -2;
        /* replace tree with p in parent[index] */
        parent->a[index] = p;
        free(tree);
@@ -993,7 +995,7 @@ const char *default_notes_ref(void)
 void init_notes(struct notes_tree *t, const char *notes_ref,
                combine_notes_fn combine_notes, int flags)
 {
-       unsigned char sha1[20], object_sha1[20];
+       struct object_id oid, object_oid;
        unsigned mode;
        struct leaf_node root_tree;
 
@@ -1017,16 +1019,16 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
        t->dirty = 0;
 
        if (flags & NOTES_INIT_EMPTY || !notes_ref ||
-           get_sha1_treeish(notes_ref, object_sha1))
+           get_sha1_treeish(notes_ref, object_oid.hash))
                return;
-       if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, object_sha1))
+       if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, object_oid.hash))
                die("Cannot use notes ref %s", notes_ref);
-       if (get_tree_entry(object_sha1, "", sha1, &mode))
+       if (get_tree_entry(object_oid.hash, "", oid.hash, &mode))
                die("Failed to read notes tree referenced by %s (%s)",
-                   notes_ref, sha1_to_hex(object_sha1));
+                   notes_ref, oid_to_hex(&object_oid));
 
        hashclr(root_tree.key_sha1);
-       hashcpy(root_tree.val_sha1, sha1);
+       hashcpy(root_tree.val_sha1, oid.hash);
        load_subtree(t, &root_tree, t->root, 0);
 }