rebase: support --no-autostash
[gitweb.git] / notes.c
diff --git a/notes.c b/notes.c
index 5f07c0b7f28e09bd2f7969ea08b00b319a226920..6a9cc6295b2e200cf35ebee1c3cc25913e20c02d 100644 (file)
--- a/notes.c
+++ b/notes.c
@@ -303,7 +303,7 @@ static int note_tree_insert(struct notes_tree *t, struct int_node *tree,
                free(entry);
                return 0;
        }
-       new_node = (struct int_node *) xcalloc(sizeof(struct int_node), 1);
+       new_node = (struct int_node *) xcalloc(1, sizeof(struct int_node));
        ret = note_tree_insert(t, new_node, n + 1, l, GET_PTR_TYPE(*p),
                               combine_notes);
        if (ret)
@@ -362,13 +362,14 @@ static int non_note_cmp(const struct non_note *a, const struct non_note *b)
        return strcmp(a->path, b->path);
 }
 
-static void add_non_note(struct notes_tree *t, const char *path,
+/* note: takes ownership of path string */
+static void add_non_note(struct notes_tree *t, char *path,
                unsigned int mode, const unsigned char *sha1)
 {
        struct non_note *p = t->prev_non_note, *n;
        n = (struct non_note *) xmalloc(sizeof(struct non_note));
        n->next = NULL;
-       n->path = xstrdup(path);
+       n->path = path;
        n->mode = mode;
        hashcpy(n->sha1, sha1);
        t->prev_non_note = n;
@@ -443,7 +444,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
                if (len <= 20) {
                        type = PTR_TYPE_NOTE;
                        l = (struct leaf_node *)
-                               xcalloc(sizeof(struct leaf_node), 1);
+                               xcalloc(1, sizeof(struct leaf_node));
                        hashcpy(l->key_sha1, object_sha1);
                        hashcpy(l->val_sha1, entry.sha1);
                        if (len < 20) {
@@ -482,17 +483,17 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
                 * component.
                 */
                {
-                       char non_note_path[PATH_MAX];
-                       char *p = non_note_path;
+                       struct strbuf non_note_path = STRBUF_INIT;
                        const char *q = sha1_to_hex(subtree->key_sha1);
                        int i;
                        for (i = 0; i < prefix_len; i++) {
-                               *p++ = *q++;
-                               *p++ = *q++;
-                               *p++ = '/';
+                               strbuf_addch(&non_note_path, *q++);
+                               strbuf_addch(&non_note_path, *q++);
+                               strbuf_addch(&non_note_path, '/');
                        }
-                       strcpy(p, entry.path);
-                       add_non_note(t, non_note_path, entry.mode, entry.sha1);
+                       strbuf_addstr(&non_note_path, entry.path);
+                       add_non_note(t, strbuf_detach(&non_note_path, NULL),
+                                    entry.mode, entry.sha1);
                }
        }
        free(buf);
@@ -1003,7 +1004,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
        if (!combine_notes)
                combine_notes = combine_notes_concatenate;
 
-       t->root = (struct int_node *) xcalloc(sizeof(struct int_node), 1);
+       t->root = (struct int_node *) xcalloc(1, sizeof(struct int_node));
        t->first_non_note = NULL;
        t->prev_non_note = NULL;
        t->ref = notes_ref ? xstrdup(notes_ref) : NULL;