]>
Commit | Line | Data |
---|---|---|
a97a7468 JS |
1 | #ifndef NOTES_H |
2 | #define NOTES_H | |
3 | ||
709f79b0 JH |
4 | /* |
5 | * Flags controlling behaviour of notes tree initialization | |
6 | * | |
7 | * Default behaviour is to initialize the notes tree from the tree object | |
8 | * specified by the given (or default) notes ref. | |
9 | */ | |
10 | #define NOTES_INIT_EMPTY 1 | |
11 | ||
12 | /* | |
13 | * Initialize internal notes tree structure with the notes tree at the given | |
14 | * ref. If given ref is NULL, the value of the $GIT_NOTES_REF environment | |
15 | * variable is used, and if that is missing, the default notes ref is used | |
16 | * ("refs/notes/commits"). | |
17 | * | |
18 | * If you need to re-intialize the internal notes tree structure (e.g. loading | |
19 | * from a different notes ref), please first de-initialize the current notes | |
20 | * tree by calling free_notes(). | |
21 | */ | |
22 | void init_notes(const char *notes_ref, int flags); | |
23 | ||
2626b536 JH |
24 | /* Add the given note object to the internal notes tree structure */ |
25 | void add_note(const unsigned char *object_sha1, | |
26 | const unsigned char *note_sha1); | |
27 | ||
1ec666b0 JH |
28 | /* Remove the given note object from the internal notes tree structure */ |
29 | void remove_note(const unsigned char *object_sha1); | |
30 | ||
9b391f21 JH |
31 | /* |
32 | * Get the note object SHA1 containing the note data for the given object | |
33 | * | |
34 | * Return NULL if the given object has no notes. | |
35 | */ | |
36 | const unsigned char *get_note(const unsigned char *object_sha1); | |
37 | ||
73f77b90 JH |
38 | /* |
39 | * Flags controlling behaviour of for_each_note() | |
40 | * | |
41 | * Default behaviour of for_each_note() is to traverse every single note object | |
42 | * in the notes tree, unpacking subtree entries along the way. | |
43 | * The following flags can be used to alter the default behaviour: | |
44 | * | |
45 | * - DONT_UNPACK_SUBTREES causes for_each_note() NOT to unpack and recurse into | |
46 | * subtree entries while traversing the notes tree. This causes notes within | |
47 | * those subtrees NOT to be passed to the callback. Use this flag if you | |
48 | * don't want to traverse _all_ notes, but only want to traverse the parts | |
49 | * of the notes tree that have already been unpacked (this includes at least | |
50 | * all notes that have been added/changed). | |
51 | * | |
52 | * - YIELD_SUBTREES causes any subtree entries that are encountered to be | |
53 | * passed to the callback, before recursing into them. Subtree entries are | |
54 | * not note objects, but represent intermediate directories in the notes | |
55 | * tree. When passed to the callback, subtree entries will have a trailing | |
56 | * slash in their path, which the callback may use to differentiate between | |
57 | * note entries and subtree entries. Note that already-unpacked subtree | |
58 | * entries are not part of the notes tree, and will therefore not be yielded. | |
59 | * If this flag is used together with DONT_UNPACK_SUBTREES, for_each_note() | |
60 | * will yield the subtree entry, but not recurse into it. | |
61 | */ | |
62 | #define FOR_EACH_NOTE_DONT_UNPACK_SUBTREES 1 | |
63 | #define FOR_EACH_NOTE_YIELD_SUBTREES 2 | |
64 | ||
65 | /* | |
66 | * Invoke the specified callback function for each note | |
67 | * | |
68 | * If the callback returns nonzero, the note walk is aborted, and the return | |
69 | * value from the callback is returned from for_each_note(). Hence, a zero | |
70 | * return value from for_each_note() indicates that all notes were walked | |
71 | * successfully. | |
72 | * | |
73 | * IMPORTANT: The callback function is NOT allowed to change the notes tree. | |
74 | * In other words, the following functions can NOT be invoked (on the current | |
75 | * notes tree) from within the callback: | |
76 | * - add_note() | |
77 | * - remove_note() | |
78 | * - free_notes() | |
79 | */ | |
80 | typedef int each_note_fn(const unsigned char *object_sha1, | |
81 | const unsigned char *note_sha1, char *note_path, | |
82 | void *cb_data); | |
83 | int for_each_note(int flags, each_note_fn fn, void *cb_data); | |
84 | ||
27d57564 JH |
85 | /* Free (and de-initialize) the internal notes tree structure */ |
86 | void free_notes(void); | |
87 | ||
a7e7eff6 | 88 | /* Flags controlling how notes are formatted */ |
c56fcc89 JH |
89 | #define NOTES_SHOW_HEADER 1 |
90 | #define NOTES_INDENT 2 | |
91 | ||
a7e7eff6 JH |
92 | /* |
93 | * Fill the given strbuf with the notes associated with the given object. | |
94 | * | |
95 | * If the internal notes structure is not initialized, it will be auto- | |
96 | * initialized to the default value (see documentation for init_notes() above). | |
97 | * | |
98 | * 'flags' is a bitwise combination of the above formatting flags. | |
99 | */ | |
100 | void format_note(const unsigned char *object_sha1, struct strbuf *sb, | |
c56fcc89 | 101 | const char *output_encoding, int flags); |
a97a7468 JS |
102 | |
103 | #endif |