| 1013 | } |
| 1014 | |
| 1015 | void init_notes(struct notes_tree *t, const char *notes_ref, |
| 1016 | combine_notes_fn combine_notes, int flags) |
| 1017 | { |
| 1018 | struct object_id oid, object_oid; |
| 1019 | unsigned short mode; |
| 1020 | struct leaf_node root_tree; |
| 1021 | char *to_free = NULL; |
| 1022 | |
| 1023 | if (!t) |
| 1024 | t = &default_notes_tree; |
| 1025 | assert(!t->initialized); |
| 1026 | |
| 1027 | if (!notes_ref) |
| 1028 | notes_ref = to_free = default_notes_ref(the_repository); |
| 1029 | update_ref_namespace(NAMESPACE_NOTES, xstrdup(notes_ref)); |
| 1030 | |
| 1031 | if (!combine_notes) |
| 1032 | combine_notes = combine_notes_concatenate; |
| 1033 | |
| 1034 | t->root = (struct int_node *) xcalloc(1, sizeof(struct int_node)); |
| 1035 | t->first_non_note = NULL; |
| 1036 | t->prev_non_note = NULL; |
| 1037 | t->ref = xstrdup(notes_ref); |
| 1038 | t->update_ref = (flags & NOTES_INIT_WRITABLE) ? t->ref : NULL; |
| 1039 | t->combine_notes = combine_notes; |
| 1040 | t->initialized = 1; |
| 1041 | t->dirty = 0; |
| 1042 | |
| 1043 | if (flags & NOTES_INIT_EMPTY || |
| 1044 | repo_get_oid_treeish(the_repository, notes_ref, &object_oid)) |
| 1045 | goto out; |
| 1046 | if (flags & NOTES_INIT_WRITABLE && refs_read_ref(get_main_ref_store(the_repository), notes_ref, &object_oid)) |
| 1047 | die("Cannot use notes ref %s", notes_ref); |
| 1048 | if (get_tree_entry(the_repository, &object_oid, "", &oid, &mode)) |
| 1049 | die("Failed to read notes tree referenced by %s (%s)", |
| 1050 | notes_ref, oid_to_hex(&object_oid)); |
| 1051 | |
| 1052 | oidclr(&root_tree.key_oid, the_repository->hash_algo); |
| 1053 | oidcpy(&root_tree.val_oid, &oid); |
| 1054 | load_subtree(t, &root_tree, t->root, 0); |
| 1055 | |
| 1056 | out: |
| 1057 | free(to_free); |
| 1058 | } |
| 1059 | |
| 1060 | struct notes_tree **load_notes_trees(struct string_list *refs, int flags) |
| 1061 | { |
no test coverage detected