7 * Encapsulates the internal notes tree structure associated with a notes ref.
8 * Whenever a struct notes_tree pointer is required below, you may pass NULL in
9 * order to use the default/internal notes tree. E.g. you only need to pass a
10 * non-NULL value if you need to refer to several different notes trees
13 extern struct notes_tree
{
14 struct int_node
*root
;
20 * Flags controlling behaviour of notes tree initialization
22 * Default behaviour is to initialize the notes tree from the tree object
23 * specified by the given (or default) notes ref.
25 #define NOTES_INIT_EMPTY 1
28 * Initialize the given notes_tree with the notes tree structure at the given
29 * ref. If given ref is NULL, the value of the $GIT_NOTES_REF environment
30 * variable is used, and if that is missing, the default notes ref is used
31 * ("refs/notes/commits").
33 * If you need to re-intialize a notes_tree structure (e.g. when switching from
34 * one notes ref to another), you must first de-initialize the notes_tree
35 * structure by calling free_notes(struct notes_tree *).
37 * If you pass t == NULL, the default internal notes_tree will be initialized.
39 * Precondition: The notes_tree structure is zeroed (this can be achieved with
40 * memset(t, 0, sizeof(struct notes_tree)))
42 void init_notes(struct notes_tree
*t
, const char *notes_ref
, int flags
);
45 * Add the given note object to the given notes_tree structure
47 * IMPORTANT: The changes made by add_note() to the given notes_tree structure
48 * are not persistent until a subsequent call to write_notes_tree() returns
51 void add_note(struct notes_tree
*t
, const unsigned char *object_sha1
,
52 const unsigned char *note_sha1
);
55 * Remove the given note object from the given notes_tree structure
57 * IMPORTANT: The changes made by remove_note() to the given notes_tree
58 * structure are not persistent until a subsequent call to write_notes_tree()
61 void remove_note(struct notes_tree
*t
, const unsigned char *object_sha1
);
64 * Get the note object SHA1 containing the note data for the given object
66 * Return NULL if the given object has no notes.
68 const unsigned char *get_note(struct notes_tree
*t
,
69 const unsigned char *object_sha1
);
72 * Flags controlling behaviour of for_each_note()
74 * Default behaviour of for_each_note() is to traverse every single note object
75 * in the given notes tree, unpacking subtree entries along the way.
76 * The following flags can be used to alter the default behaviour:
78 * - DONT_UNPACK_SUBTREES causes for_each_note() NOT to unpack and recurse into
79 * subtree entries while traversing the notes tree. This causes notes within
80 * those subtrees NOT to be passed to the callback. Use this flag if you
81 * don't want to traverse _all_ notes, but only want to traverse the parts
82 * of the notes tree that have already been unpacked (this includes at least
83 * all notes that have been added/changed).
85 * - YIELD_SUBTREES causes any subtree entries that are encountered to be
86 * passed to the callback, before recursing into them. Subtree entries are
87 * not note objects, but represent intermediate directories in the notes
88 * tree. When passed to the callback, subtree entries will have a trailing
89 * slash in their path, which the callback may use to differentiate between
90 * note entries and subtree entries. Note that already-unpacked subtree
91 * entries are not part of the notes tree, and will therefore not be yielded.
92 * If this flag is used together with DONT_UNPACK_SUBTREES, for_each_note()
93 * will yield the subtree entry, but not recurse into it.
95 #define FOR_EACH_NOTE_DONT_UNPACK_SUBTREES 1
96 #define FOR_EACH_NOTE_YIELD_SUBTREES 2
99 * Invoke the specified callback function for each note in the given notes_tree
101 * If the callback returns nonzero, the note walk is aborted, and the return
102 * value from the callback is returned from for_each_note(). Hence, a zero
103 * return value from for_each_note() indicates that all notes were walked
106 * IMPORTANT: The callback function is NOT allowed to change the notes tree.
107 * In other words, the following functions can NOT be invoked (on the current
108 * notes tree) from within the callback:
113 typedef int each_note_fn(const unsigned char *object_sha1
,
114 const unsigned char *note_sha1
, char *note_path
,
116 int for_each_note(struct notes_tree
*t
, int flags
, each_note_fn fn
,
120 * Write the given notes_tree structure to the object database
122 * Creates a new tree object encapsulating the current state of the given
123 * notes_tree, and stores its SHA1 into the 'result' argument.
125 * Returns zero on success, non-zero on failure.
127 * IMPORTANT: Changes made to the given notes_tree are not persistent until
128 * this function has returned zero. Please also remember to create a
129 * corresponding commit object, and update the appropriate notes ref.
131 int write_notes_tree(struct notes_tree
*t
, unsigned char *result
);
134 * Free (and de-initialize) the given notes_tree structure
136 * IMPORTANT: Changes made to the given notes_tree since the last, successful
137 * call to write_notes_tree() will be lost.
139 void free_notes(struct notes_tree
*t
);
141 /* Flags controlling how notes are formatted */
142 #define NOTES_SHOW_HEADER 1
143 #define NOTES_INDENT 2
146 * Fill the given strbuf with the notes associated with the given object.
148 * If the given notes_tree structure is not initialized, it will be auto-
149 * initialized to the default value (see documentation for init_notes() above).
150 * If the given notes_tree is NULL, the internal/default notes_tree will be
153 * 'flags' is a bitwise combination of the above formatting flags.
155 void format_note(struct notes_tree
*t
, const unsigned char *object_sha1
,
156 struct strbuf
*sb
, const char *output_encoding
, int flags
);