Skip to content

Commit d621024

Browse files
authored
Merge pull request libgit2#4159 from richardipsum/notes-commit
Support using notes via a commit rather than a ref
2 parents 8cdf439 + 4623c25 commit d621024

File tree

3 files changed

+527
-48
lines changed

3 files changed

+527
-48
lines changed

include/git2/notes.h

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ GIT_EXTERN(int) git_note_iterator_new(
5151
git_repository *repo,
5252
const char *notes_ref);
5353

54+
/**
55+
* Creates a new iterator for notes from a commit
56+
*
57+
* The iterator must be freed manually by the user.
58+
*
59+
* @param out pointer to the iterator
60+
* @param notes_commit a pointer to the notes commit object
61+
*
62+
* @return 0 or an error code
63+
*/
64+
GIT_EXTERN(int) git_note_commit_iterator_new(
65+
git_note_iterator **out,
66+
git_commit *notes_commit);
67+
5468
/**
5569
* Frees an git_note_iterator
5670
*
@@ -94,6 +108,25 @@ GIT_EXTERN(int) git_note_read(
94108
const char *notes_ref,
95109
const git_oid *oid);
96110

111+
112+
/**
113+
* Read the note for an object from a note commit
114+
*
115+
* The note must be freed manually by the user.
116+
*
117+
* @param out pointer to the read note; NULL in case of error
118+
* @param repo repository where to look up the note
119+
* @param notes_commit a pointer to the notes commit object
120+
* @param oid OID of the git object to read the note from
121+
*
122+
* @return 0 or an error code
123+
*/
124+
GIT_EXTERN(int) git_note_commit_read(
125+
git_note **out,
126+
git_repository *repo,
127+
git_commit *notes_commit,
128+
const git_oid *oid);
129+
97130
/**
98131
* Get the note author
99132
*
@@ -153,6 +186,36 @@ GIT_EXTERN(int) git_note_create(
153186
const char *note,
154187
int force);
155188

189+
/**
190+
* Add a note for an object from a commit
191+
*
192+
* This function will create a notes commit for a given object,
193+
* the commit is a dangling commit, no reference is created.
194+
*
195+
* @param notes_commit_out pointer to store the commit (optional);
196+
* NULL in case of error
197+
* @param notes_blob_out a point to the id of a note blob (optional)
198+
* @param repo repository where the note will live
199+
* @param parent Pointer to parent note
200+
* or NULL if this shall start a new notes tree
201+
* @param author signature of the notes commit author
202+
* @param committer signature of the notes commit committer
203+
* @param oid OID of the git object to decorate
204+
* @param note Content of the note to add for object oid
205+
* @param allow_note_overwrite Overwrite existing note
206+
*
207+
* @return 0 or an error code
208+
*/
209+
GIT_EXTERN(int) git_note_commit_create(
210+
git_oid *notes_commit_out,
211+
git_oid *notes_blob_out,
212+
git_repository *repo,
213+
git_commit *parent,
214+
const git_signature *author,
215+
const git_signature *committer,
216+
const git_oid *oid,
217+
const char *note,
218+
int allow_note_overwrite);
156219

157220
/**
158221
* Remove the note for an object
@@ -173,6 +236,32 @@ GIT_EXTERN(int) git_note_remove(
173236
const git_signature *committer,
174237
const git_oid *oid);
175238

239+
/**
240+
* Remove the note for an object
241+
*
242+
* @param notes_commit_out pointer to store the new notes commit (optional);
243+
* NULL in case of error.
244+
* When removing a note a new tree containing all notes
245+
* sans the note to be removed is created and a new commit
246+
* pointing to that tree is also created.
247+
* In the case where the resulting tree is an empty tree
248+
* a new commit pointing to this empty tree will be returned.
249+
* @param repo repository where the note lives
250+
* @param notes_commit a pointer to the notes commit object
251+
* @param author signature of the notes commit author
252+
* @param committer signature of the notes commit committer
253+
* @param oid OID of the git object to remove the note from
254+
*
255+
* @return 0 or an error code
256+
*/
257+
GIT_EXTERN(int) git_note_commit_remove(
258+
git_oid *notes_commit_out,
259+
git_repository *repo,
260+
git_commit *notes_commit,
261+
const git_signature *author,
262+
const git_signature *committer,
263+
const git_oid *oid);
264+
176265
/**
177266
* Free a git_note object
178267
*

0 commit comments

Comments
 (0)