summaryrefslogtreecommitdiff
path: root/note.go
diff options
context:
space:
mode:
authorCarlos Martín Nieto <[email protected]>2015-08-31 13:49:17 +0200
committerCarlos Martín Nieto <[email protected]>2015-08-31 13:55:46 +0200
commitf72db33baf9a47fc8b0d0ad8e83881eba235b532 (patch)
tree0869cd25b8ea03495f35bcb42eb908cc72afb6af /note.go
parent157593f38da780c4f6cb6dc61275b9b36a3327bf (diff)
parentc6c2e9389fd2148d20f2e283000f5b4204dbcdc8 (diff)
Merge branch 'next'
Diffstat (limited to 'note.go')
-rw-r--r--note.go121
1 files changed, 121 insertions, 0 deletions
diff --git a/note.go b/note.go
index 3cdd340..a1b15d8 100644
--- a/note.go
+++ b/note.go
@@ -10,6 +10,127 @@ import (
"unsafe"
)
+// This object represents the possible operations which can be
+// performed on the collection of notes for a repository.
+type NoteCollection struct {
+ repo *Repository
+}
+
+// Create adds a note for an object
+func (c *NoteCollection) Create(
+ ref string, author, committer *Signature, id *Oid,
+ note string, force bool) (*Oid, error) {
+
+ oid := new(Oid)
+
+ var cref *C.char
+ if ref == "" {
+ cref = nil
+ } else {
+ cref = C.CString(ref)
+ defer C.free(unsafe.Pointer(cref))
+ }
+
+ authorSig, err := author.toC()
+ if err != nil {
+ return nil, err
+ }
+ defer C.git_signature_free(authorSig)
+
+ committerSig, err := committer.toC()
+ if err != nil {
+ return nil, err
+ }
+ defer C.git_signature_free(committerSig)
+
+ cnote := C.CString(note)
+ defer C.free(unsafe.Pointer(cnote))
+
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ ret := C.git_note_create(
+ oid.toC(), c.repo.ptr, cref, authorSig,
+ committerSig, id.toC(), cnote, cbool(force))
+
+ if ret < 0 {
+ return nil, MakeGitError(ret)
+ }
+ return oid, nil
+}
+
+// Read reads the note for an object
+func (c *NoteCollection) Read(ref string, id *Oid) (*Note, error) {
+ var cref *C.char
+ if ref == "" {
+ cref = nil
+ } else {
+ cref = C.CString(ref)
+ defer C.free(unsafe.Pointer(cref))
+ }
+
+ note := new(Note)
+
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ if ret := C.git_note_read(&note.ptr, c.repo.ptr, cref, id.toC()); ret < 0 {
+ return nil, MakeGitError(ret)
+ }
+
+ runtime.SetFinalizer(note, (*Note).Free)
+ return note, nil
+}
+
+// Remove removes the note for an object
+func (c *NoteCollection) Remove(ref string, author, committer *Signature, id *Oid) error {
+ var cref *C.char
+ if ref == "" {
+ cref = nil
+ } else {
+ cref = C.CString(ref)
+ defer C.free(unsafe.Pointer(cref))
+ }
+
+ authorSig, err := author.toC()
+ if err != nil {
+ return err
+ }
+ defer C.git_signature_free(authorSig)
+
+ committerSig, err := committer.toC()
+ if err != nil {
+ return err
+ }
+ defer C.git_signature_free(committerSig)
+
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ ret := C.git_note_remove(c.repo.ptr, cref, authorSig, committerSig, id.toC())
+ if ret < 0 {
+ return MakeGitError(ret)
+ }
+ return nil
+}
+
+// DefaultRef returns the default notes reference for a repository
+func (c *NoteCollection) DefaultRef() (string, error) {
+ buf := C.git_buf{}
+
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ if ret := C.git_note_default_ref(&buf, c.repo.ptr); ret < 0 {
+ return "", MakeGitError(ret)
+ }
+
+ ret := C.GoString(buf.ptr)
+ C.git_buf_free(&buf)
+
+ return ret, nil
+}
+
// Note
type Note struct {
ptr *C.git_note