c49b7a512f541f058022530e59cf750db8308b43
   1#ifndef NOTES_H
   2#define NOTES_H
   3
   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 */
  22void init_notes(const char *notes_ref, int flags);
  23
  24/*
  25 * Add the given note object to the internal notes tree structure
  26 *
  27 * IMPORTANT: The changes made by add_note() to the internal notes tree structure
  28 * are not persistent until a subsequent call to write_notes_tree() returns
  29 * zero.
  30 */
  31void add_note(const unsigned char *object_sha1,
  32                const unsigned char *note_sha1);
  33
  34/*
  35 * Remove the given note object from the internal notes tree structure
  36 *
  37 * IMPORTANT: The changes made by remove_note() to the internal notes tree
  38 * structure are not persistent until a subsequent call to write_notes_tree()
  39 * returns zero.
  40 */
  41void remove_note(const unsigned char *object_sha1);
  42
  43/*
  44 * Get the note object SHA1 containing the note data for the given object
  45 *
  46 * Return NULL if the given object has no notes.
  47 */
  48const unsigned char *get_note(const unsigned char *object_sha1);
  49
  50/*
  51 * Flags controlling behaviour of for_each_note()
  52 *
  53 * Default behaviour of for_each_note() is to traverse every single note object
  54 * in the notes tree, unpacking subtree entries along the way.
  55 * The following flags can be used to alter the default behaviour:
  56 *
  57 * - DONT_UNPACK_SUBTREES causes for_each_note() NOT to unpack and recurse into
  58 *   subtree entries while traversing the notes tree. This causes notes within
  59 *   those subtrees NOT to be passed to the callback. Use this flag if you
  60 *   don't want to traverse _all_ notes, but only want to traverse the parts
  61 *   of the notes tree that have already been unpacked (this includes at least
  62 *   all notes that have been added/changed).
  63 *
  64 * - YIELD_SUBTREES causes any subtree entries that are encountered to be
  65 *   passed to the callback, before recursing into them. Subtree entries are
  66 *   not note objects, but represent intermediate directories in the notes
  67 *   tree. When passed to the callback, subtree entries will have a trailing
  68 *   slash in their path, which the callback may use to differentiate between
  69 *   note entries and subtree entries. Note that already-unpacked subtree
  70 *   entries are not part of the notes tree, and will therefore not be yielded.
  71 *   If this flag is used together with DONT_UNPACK_SUBTREES, for_each_note()
  72 *   will yield the subtree entry, but not recurse into it.
  73 */
  74#define FOR_EACH_NOTE_DONT_UNPACK_SUBTREES 1
  75#define FOR_EACH_NOTE_YIELD_SUBTREES 2
  76
  77/*
  78 * Invoke the specified callback function for each note
  79 *
  80 * If the callback returns nonzero, the note walk is aborted, and the return
  81 * value from the callback is returned from for_each_note(). Hence, a zero
  82 * return value from for_each_note() indicates that all notes were walked
  83 * successfully.
  84 *
  85 * IMPORTANT: The callback function is NOT allowed to change the notes tree.
  86 * In other words, the following functions can NOT be invoked (on the current
  87 * notes tree) from within the callback:
  88 * - add_note()
  89 * - remove_note()
  90 * - free_notes()
  91 */
  92typedef int each_note_fn(const unsigned char *object_sha1,
  93                const unsigned char *note_sha1, char *note_path,
  94                void *cb_data);
  95int for_each_note(int flags, each_note_fn fn, void *cb_data);
  96
  97/*
  98 * Write the internal notes tree structure to the object database
  99 *
 100 * Creates a new tree object encapsulating the current state of the
 101 * internal notes tree, and stores its SHA1 into the 'result' argument.
 102 *
 103 * Returns zero on success, non-zero on failure.
 104 *
 105 * IMPORTANT: Changes made to the internal notes tree structure are not
 106 * persistent until this function has returned zero. Please also remember
 107 * to create a corresponding commit object, and update the appropriate
 108 * notes ref.
 109 */
 110int write_notes_tree(unsigned char *result);
 111
 112/*
 113 * Free (and de-initialize) the internal notes tree structure
 114 *
 115 * IMPORTANT: Changes made to the notes tree since the last, successful
 116 * call to write_notes_tree() will be lost.
 117 */
 118void free_notes(void);
 119
 120/* Flags controlling how notes are formatted */
 121#define NOTES_SHOW_HEADER 1
 122#define NOTES_INDENT 2
 123
 124/*
 125 * Fill the given strbuf with the notes associated with the given object.
 126 *
 127 * If the internal notes structure is not initialized, it will be auto-
 128 * initialized to the default value (see documentation for init_notes() above).
 129 *
 130 * 'flags' is a bitwise combination of the above formatting flags.
 131 */
 132void format_note(const unsigned char *object_sha1, struct strbuf *sb,
 133                const char *output_encoding, int flags);
 134
 135#endif