Commit 76a60dfb authored by Carlos Martín Nieto's avatar Carlos Martín Nieto

Third round of keep-alive aditions

parent 7c587b52
......@@ -18,10 +18,11 @@ import (
type AnnotatedCommit struct {
ptr *C.git_annotated_commit
r *Repository
}
func newAnnotatedCommitFromC(c *C.git_annotated_commit) *AnnotatedCommit {
mh := &AnnotatedCommit{ptr: c}
func newAnnotatedCommitFromC(ptr *C.git_annotated_commit, r *Repository) *AnnotatedCommit {
mh := &AnnotatedCommit{ptr: ptr, r: r}
runtime.SetFinalizer(mh, (*AnnotatedCommit).Free)
return mh
}
......@@ -32,8 +33,6 @@ func (mh *AnnotatedCommit) Free() {
}
func (r *Repository) AnnotatedCommitFromFetchHead(branchName string, remoteURL string, oid *Oid) (*AnnotatedCommit, error) {
mh := &AnnotatedCommit{}
cbranchName := C.CString(branchName)
defer C.free(unsafe.Pointer(cbranchName))
......@@ -43,40 +42,41 @@ func (r *Repository) AnnotatedCommitFromFetchHead(branchName string, remoteURL s
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_annotated_commit_from_fetchhead(&mh.ptr, r.ptr, cbranchName, cremoteURL, oid.toC())
var ptr *C.git_annotated_commit
ret := C.git_annotated_commit_from_fetchhead(&ptr, r.ptr, cbranchName, cremoteURL, oid.toC())
runtime.KeepAlive(oid)
if ret < 0 {
return nil, MakeGitError(ret)
}
runtime.SetFinalizer(mh, (*AnnotatedCommit).Free)
return mh, nil
return newAnnotatedCommitFromC(ptr, r), nil
}
func (r *Repository) LookupAnnotatedCommit(oid *Oid) (*AnnotatedCommit, error) {
mh := &AnnotatedCommit{}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_annotated_commit_lookup(&mh.ptr, r.ptr, oid.toC())
var ptr *C.git_annotated_commit
ret := C.git_annotated_commit_lookup(&ptr, r.ptr, oid.toC())
runtime.KeepAlive(oid)
if ret < 0 {
return nil, MakeGitError(ret)
}
runtime.SetFinalizer(mh, (*AnnotatedCommit).Free)
return mh, nil
return newAnnotatedCommitFromC(ptr, r), nil
}
func (r *Repository) AnnotatedCommitFromRef(ref *Reference) (*AnnotatedCommit, error) {
mh := &AnnotatedCommit{}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_annotated_commit_from_ref(&mh.ptr, r.ptr, ref.ptr)
var ptr *C.git_annotated_commit
ret := C.git_annotated_commit_from_ref(&ptr, r.ptr, ref.ptr)
runtime.KeepAlive(r)
runtime.KeepAlive(ref)
if ret < 0 {
return nil, MakeGitError(ret)
}
runtime.SetFinalizer(mh, (*AnnotatedCommit).Free)
return mh, nil
return newAnnotatedCommitFromC(ptr, r), nil
}
type MergeTreeFlag int
......@@ -162,6 +162,7 @@ func (r *Repository) Merge(theirHeads []*AnnotatedCommit, mergeOptions *MergeOpt
}
ptr := unsafe.Pointer(&gmerge_head_array[0])
err := C.git_merge(r.ptr, (**C.git_annotated_commit)(ptr), C.size_t(len(theirHeads)), cMergeOpts, cCheckoutOpts)
runtime.KeepAlive(theirHeads)
if err < 0 {
return MakeGitError(err)
}
......@@ -201,6 +202,7 @@ func (r *Repository) MergeAnalysis(theirHeads []*AnnotatedCommit) (MergeAnalysis
var analysis C.git_merge_analysis_t
var preference C.git_merge_preference_t
err := C.git_merge_analysis(&analysis, &preference, r.ptr, (**C.git_annotated_commit)(ptr), C.size_t(len(theirHeads)))
runtime.KeepAlive(theirHeads)
if err < 0 {
return MergeAnalysisNone, MergePreferenceNone, MakeGitError(err)
}
......@@ -214,14 +216,15 @@ func (r *Repository) MergeCommits(ours *Commit, theirs *Commit, options *MergeOp
copts := options.toC()
idx := &Index{}
ret := C.git_merge_commits(&idx.ptr, r.ptr, ours.cast_ptr, theirs.cast_ptr, copts)
var ptr *C.git_index
ret := C.git_merge_commits(&ptr, r.ptr, ours.cast_ptr, theirs.cast_ptr, copts)
runtime.KeepAlive(ours)
runtime.KeepAlive(theirs)
if ret < 0 {
return nil, MakeGitError(ret)
}
runtime.SetFinalizer(idx, (*Index).Free)
return idx, nil
return newIndexFromC(ptr, r), nil
}
func (r *Repository) MergeTrees(ancestor *Tree, ours *Tree, theirs *Tree, options *MergeOptions) (*Index, error) {
......@@ -230,17 +233,20 @@ func (r *Repository) MergeTrees(ancestor *Tree, ours *Tree, theirs *Tree, option
copts := options.toC()
idx := &Index{}
var ancestor_ptr *C.git_tree
if ancestor != nil {
ancestor_ptr = ancestor.cast_ptr
}
ret := C.git_merge_trees(&idx.ptr, r.ptr, ancestor_ptr, ours.cast_ptr, theirs.cast_ptr, copts)
var ptr *C.git_index
ret := C.git_merge_trees(&ptr, r.ptr, ancestor_ptr, ours.cast_ptr, theirs.cast_ptr, copts)
runtime.KeepAlive(ancestor)
runtime.KeepAlive(ours)
runtime.KeepAlive(theirs)
if ret < 0 {
return nil, MakeGitError(ret)
}
runtime.SetFinalizer(idx, (*Index).Free)
return idx, nil
return newIndexFromC(ptr, r), nil
}
func (r *Repository) MergeBase(one *Oid, two *Oid) (*Oid, error) {
......@@ -249,6 +255,9 @@ func (r *Repository) MergeBase(one *Oid, two *Oid) (*Oid, error) {
var oid C.git_oid
ret := C.git_merge_base(&oid, r.ptr, one.toC(), two.toC())
runtime.KeepAlive(one)
runtime.KeepAlive(two)
runtime.KeepAlive(r)
if ret < 0 {
return nil, MakeGitError(ret)
}
......@@ -265,6 +274,8 @@ func (r *Repository) MergeBases(one, two *Oid) ([]*Oid, error) {
var coids C.git_oidarray
ret := C.git_merge_bases(&coids, r.ptr, one.toC(), two.toC())
runtime.KeepAlive(one)
runtime.KeepAlive(two)
if ret < 0 {
return make([]*Oid, 0), MakeGitError(ret)
}
......@@ -413,6 +424,9 @@ func MergeFile(ancestor MergeFileInput, ours MergeFileInput, theirs MergeFileInp
(*C.char)(unsafe.Pointer(oursContents)), C.size_t(len(ours.Contents)), oursPath, C.uint(ours.Mode),
(*C.char)(unsafe.Pointer(theirsContents)), C.size_t(len(theirs.Contents)), theirsPath, C.uint(theirs.Mode),
copts)
runtime.KeepAlive(ancestor)
runtime.KeepAlive(ours)
runtime.KeepAlive(theirs)
if ecode < 0 {
return nil, MakeGitError(ecode)
}
......
......@@ -52,7 +52,8 @@ func (c *NoteCollection) Create(
ret := C.git_note_create(
oid.toC(), c.repo.ptr, cref, authorSig,
committerSig, id.toC(), cnote, cbool(force))
runtime.KeepAlive(c)
runtime.KeepAlive(id)
if ret < 0 {
return nil, MakeGitError(ret)
}
......@@ -69,17 +70,18 @@ func (c *NoteCollection) Read(ref string, id *Oid) (*Note, error) {
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 {
var ptr *C.git_note
ret := C.git_note_read(&ptr, c.repo.ptr, cref, id.toC())
runtime.KeepAlive(c)
runtime.KeepAlive(id)
if ret < 0 {
return nil, MakeGitError(ret)
}
runtime.SetFinalizer(note, (*Note).Free)
return note, nil
return newNoteFromC(ptr, c.repo), nil
}
// Remove removes the note for an object
......@@ -108,6 +110,8 @@ func (c *NoteCollection) Remove(ref string, author, committer *Signature, id *Oi
defer runtime.UnlockOSThread()
ret := C.git_note_remove(c.repo.ptr, cref, authorSig, committerSig, id.toC())
runtime.KeepAlive(c)
runtime.KeepAlive(id)
if ret < 0 {
return MakeGitError(ret)
}
......@@ -121,8 +125,10 @@ func (c *NoteCollection) DefaultRef() (string, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
if ret := C.git_note_default_ref(&buf, c.repo.ptr); ret < 0 {
return "", MakeGitError(ret)
ecode := C.git_note_default_ref(&buf, c.repo.ptr)
runtime.KeepAlive(c)
if ecode < 0 {
return "", MakeGitError(ecode)
}
ret := C.GoString(buf.ptr)
......@@ -134,6 +140,13 @@ func (c *NoteCollection) DefaultRef() (string, error) {
// Note
type Note struct {
ptr *C.git_note
r *Repository
}
func newNoteFromC(ptr *C.git_note, r *Repository) *Note {
note := &Note{ptr: ptr, r: r}
runtime.SetFinalizer(note, (*Note).Free)
return note
}
// Free frees a git_note object
......@@ -156,23 +169,28 @@ func (n *Note) Author() *Signature {
// Id returns the note object's id
func (n *Note) Id() *Oid {
ptr := C.git_note_id(n.ptr)
runtime.KeepAlive(n)
return newOidFromC(ptr)
}
// Committer returns the signature of the note committer
func (n *Note) Committer() *Signature {
ptr := C.git_note_committer(n.ptr)
runtime.KeepAlive(n)
return newSignatureFromC(ptr)
}
// Message returns the note message
func (n *Note) Message() string {
return C.GoString(C.git_note_message(n.ptr))
ret := C.GoString(C.git_note_message(n.ptr))
runtime.KeepAlive(n)
return ret
}
// NoteIterator
type NoteIterator struct {
ptr *C.git_note_iterator
r *Repository
}
// NewNoteIterator creates a new iterator for notes
......@@ -190,11 +208,13 @@ func (repo *Repository) NewNoteIterator(ref string) (*NoteIterator, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
if ret := C.git_note_iterator_new(&ptr, repo.ptr, cref); ret < 0 {
ret := C.git_note_iterator_new(&ptr, repo.ptr, cref)
runtime.KeepAlive(repo)
if ret < 0 {
return nil, MakeGitError(ret)
}
iter := &NoteIterator{ptr: ptr}
iter := &NoteIterator{ptr: ptr, r: repo}
runtime.SetFinalizer(iter, (*NoteIterator).Free)
return iter, nil
}
......@@ -213,7 +233,11 @@ func (it *NoteIterator) Next() (noteId, annotatedId *Oid, err error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
if ret := C.git_note_next(noteId.toC(), annotatedId.toC(), it.ptr); ret < 0 {
ret := C.git_note_next(noteId.toC(), annotatedId.toC(), it.ptr)
runtime.KeepAlive(noteId)
runtime.KeepAlive(annotatedId)
runtime.KeepAlive(it)
if ret < 0 {
err = MakeGitError(ret)
}
return
......
......@@ -46,7 +46,9 @@ func (t ObjectType) String() string {
}
func (o *Object) Id() *Oid {
return newOidFromC(C.git_object_id(o.ptr))
ret := newOidFromC(C.git_object_id(o.ptr))
runtime.KeepAlive(o)
return ret
}
func (o *Object) ShortId() (string, error) {
......@@ -56,6 +58,7 @@ func (o *Object) ShortId() (string, error) {
defer runtime.UnlockOSThread()
ecode := C.git_object_short_id(&resultBuf, o.ptr)
runtime.KeepAlive(o)
if ecode < 0 {
return "", MakeGitError(ecode)
}
......@@ -64,15 +67,19 @@ func (o *Object) ShortId() (string, error) {
}
func (o *Object) Type() ObjectType {
return ObjectType(C.git_object_type(o.ptr))
ret := ObjectType(C.git_object_type(o.ptr))
runtime.KeepAlive(o)
return ret
}
// Owner returns a weak reference to the repository which owns this
// object. This won't keep the underlying repository alive.
func (o *Object) Owner() *Repository {
return &Repository{
ret := &Repository{
ptr: C.git_object_owner(o.ptr),
}
runtime.KeepAlive(o)
return ret
}
func dupObject(obj *Object, kind ObjectType) (*C.git_object, error) {
......@@ -85,7 +92,9 @@ func dupObject(obj *Object, kind ObjectType) (*C.git_object, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
if err := C.git_object_dup(&cobj, obj.ptr); err < 0 {
err := C.git_object_dup(&cobj, obj.ptr)
runtime.KeepAlive(obj)
if err < 0 {
return nil, MakeGitError(err)
}
......@@ -203,7 +212,9 @@ func (o *Object) Peel(t ObjectType) (*Object, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
if err := C.git_object_peel(&cobj, o.ptr, C.git_otype(t)); err < 0 {
err := C.git_object_peel(&cobj, o.ptr, C.git_otype(t))
runtime.KeepAlive(o)
if err < 0 {
return nil, MakeGitError(err)
}
......
......@@ -47,6 +47,7 @@ func (v *Odb) AddBackend(backend *OdbBackend, priority int) (err error) {
defer runtime.UnlockOSThread()
ret := C.git_odb_add_backend(v.ptr, backend.ptr, C.int(priority))
runtime.KeepAlive(v)
if ret < 0 {
backend.Free()
return MakeGitError(ret)
......@@ -57,20 +58,23 @@ func (v *Odb) AddBackend(backend *OdbBackend, priority int) (err error) {
func (v *Odb) ReadHeader(oid *Oid) (uint64, ObjectType, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
var sz C.size_t
var cotype C.git_otype
var cotype C.git_otype
ret := C.git_odb_read_header(&sz, &cotype, v.ptr, oid.toC())
runtime.KeepAlive(v)
if ret < 0 {
return 0, C.GIT_OBJ_BAD, MakeGitError(ret)
}
return uint64(sz), ObjectType(cotype), nil
}
func (v *Odb) Exists(oid *Oid) bool {
ret := C.git_odb_exists(v.ptr, oid.toC())
runtime.KeepAlive(v)
runtime.KeepAlive(oid)
return ret != 0
}
......@@ -85,7 +89,7 @@ func (v *Odb) Write(data []byte, otype ObjectType) (oid *Oid, err error) {
defer runtime.UnlockOSThread()
ret := C.git_odb_write(oid.toC(), v.ptr, cptr, C.size_t(len(data)), C.git_otype(otype))
runtime.KeepAlive(v)
if ret < 0 {
return nil, MakeGitError(ret)
}
......@@ -100,6 +104,8 @@ func (v *Odb) Read(oid *Oid) (obj *OdbObject, err error) {
defer runtime.UnlockOSThread()
ret := C.git_odb_read(&obj.ptr, v.ptr, oid.toC())
runtime.KeepAlive(v)
runtime.KeepAlive(oid)
if ret < 0 {
return nil, MakeGitError(ret)
}
......@@ -145,6 +151,7 @@ func (v *Odb) ForEach(callback OdbForEachCallback) error {
defer pointerHandles.Untrack(handle)
ret := C._go_git_odb_foreach(v.ptr, handle)
runtime.KeepAlive(v)
if ret == C.GIT_EUSER {
return data.err
} else if ret < 0 {
......@@ -164,6 +171,7 @@ func (v *Odb) Hash(data []byte, otype ObjectType) (oid *Oid, err error) {
defer runtime.UnlockOSThread()
ret := C.git_odb_hash(oid.toC(), ptr, C.size_t(header.Len), C.git_otype(otype))
runtime.KeepAlive(data)
if ret < 0 {
return nil, MakeGitError(ret)
}
......@@ -179,6 +187,8 @@ func (v *Odb) NewReadStream(id *Oid) (*OdbReadStream, error) {
defer runtime.UnlockOSThread()
ret := C.git_odb_open_rstream(&stream.ptr, v.ptr, id.toC())
runtime.KeepAlive(v)
runtime.KeepAlive(id)
if ret < 0 {
return nil, MakeGitError(ret)
}
......@@ -197,6 +207,7 @@ func (v *Odb) NewWriteStream(size int64, otype ObjectType) (*OdbWriteStream, err
defer runtime.UnlockOSThread()
ret := C.git_odb_open_wstream(&stream.ptr, v.ptr, C.git_off_t(size), C.git_otype(otype))
runtime.KeepAlive(v)
if ret < 0 {
return nil, MakeGitError(ret)
}
......@@ -219,17 +230,25 @@ func (v *OdbObject) Free() {
}
func (object *OdbObject) Id() (oid *Oid) {
return newOidFromC(C.git_odb_object_id(object.ptr))
ret := newOidFromC(C.git_odb_object_id(object.ptr))
runtime.KeepAlive(object)
return ret
}
func (object *OdbObject) Len() (len uint64) {
return uint64(C.git_odb_object_size(object.ptr))
ret := uint64(C.git_odb_object_size(object.ptr))
runtime.KeepAlive(object)
return ret
}
func (object *OdbObject) Type() ObjectType {
return ObjectType(C.git_odb_object_type(object.ptr))
ret := ObjectType(C.git_odb_object_type(object.ptr))
runtime.KeepAlive(object)
return ret
}
// Data returns a slice pointing to the unmanaged object memory. You must make
// sure the object is referenced for at least as long as the slice is used.
func (object *OdbObject) Data() (data []byte) {
var c_blob unsafe.Pointer = C.git_odb_object_data(object.ptr)
var blob []byte
......@@ -258,6 +277,7 @@ func (stream *OdbReadStream) Read(data []byte) (int, error) {
defer runtime.UnlockOSThread()
ret := C.git_odb_stream_read(stream.ptr, ptr, size)
runtime.KeepAlive(stream)
if ret < 0 {
return 0, MakeGitError(ret)
}
......@@ -293,6 +313,7 @@ func (stream *OdbWriteStream) Write(data []byte) (int, error) {
defer runtime.UnlockOSThread()
ret := C.git_odb_stream_write(stream.ptr, ptr, size)
runtime.KeepAlive(stream)
if ret < 0 {
return 0, MakeGitError(ret)
}
......@@ -307,6 +328,7 @@ func (stream *OdbWriteStream) Close() error {
defer runtime.UnlockOSThread()
ret := C.git_odb_stream_finalize_write(stream.Id.toC(), stream.ptr)
runtime.KeepAlive(stream)
if ret < 0 {
return MakeGitError(ret)
}
......
......@@ -17,20 +17,25 @@ import (
type Packbuilder struct {
ptr *C.git_packbuilder
r *Repository
}
func (repo *Repository) NewPackbuilder() (*Packbuilder, error) {
builder := &Packbuilder{}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_packbuilder_new(&builder.ptr, repo.ptr)
var ptr *C.git_packbuilder
ret := C.git_packbuilder_new(&ptr, repo.ptr)
if ret != 0 {
return nil, MakeGitError(ret)
}
runtime.SetFinalizer(builder, (*Packbuilder).Free)
return builder, nil
return newPackbuilderFromC(ptr, repo), nil
}
func newPackbuilderFromC(ptr *C.git_packbuilder, r *Repository) *Packbuilder {
pb := &Packbuilder{ptr: ptr, r: r}
runtime.SetFinalizer(pb, (*Packbuilder).Free)
return pb
}
func (pb *Packbuilder) Free() {
......@@ -46,6 +51,8 @@ func (pb *Packbuilder) Insert(id *Oid, name string) error {
defer runtime.UnlockOSThread()
ret := C.git_packbuilder_insert(pb.ptr, id.toC(), cname)
runtime.KeepAlive(pb)
runtime.KeepAlive(id)
if ret != 0 {
return MakeGitError(ret)
}
......@@ -57,6 +64,8 @@ func (pb *Packbuilder) InsertCommit(id *Oid) error {
defer runtime.UnlockOSThread()
ret := C.git_packbuilder_insert_commit(pb.ptr, id.toC())
runtime.KeepAlive(pb)
runtime.KeepAlive(id)
if ret != 0 {
return MakeGitError(ret)
}
......@@ -68,6 +77,8 @@ func (pb *Packbuilder) InsertTree(id *Oid) error {
defer runtime.UnlockOSThread()
ret := C.git_packbuilder_insert_tree(pb.ptr, id.toC())
runtime.KeepAlive(pb)
runtime.KeepAlive(id)
if ret != 0 {
return MakeGitError(ret)
}
......@@ -75,7 +86,9 @@ func (pb *Packbuilder) InsertTree(id *Oid) error {
}
func (pb *Packbuilder) ObjectCount() uint32 {
return uint32(C.git_packbuilder_object_count(pb.ptr))
ret := uint32(C.git_packbuilder_object_count(pb.ptr))
runtime.KeepAlive(pb)
return ret
}
func (pb *Packbuilder) WriteToFile(name string, mode os.FileMode) error {
......@@ -86,6 +99,7 @@ func (pb *Packbuilder) WriteToFile(name string, mode os.FileMode) error {
defer runtime.UnlockOSThread()
ret := C.git_packbuilder_write(pb.ptr, cname, C.uint(mode.Perm()), nil, nil)
runtime.KeepAlive(pb)
if ret != 0 {
return MakeGitError(ret)
}
......@@ -100,7 +114,9 @@ func (pb *Packbuilder) Write(w io.Writer) error {
}
func (pb *Packbuilder) Written() uint32 {
return uint32(C.git_packbuilder_written(pb.ptr))
ret := uint32(C.git_packbuilder_written(pb.ptr))
runtime.KeepAlive(pb)
return ret
}
type PackbuilderForeachCallback func([]byte) error
......@@ -142,6 +158,7 @@ func (pb *Packbuilder) ForEach(callback PackbuilderForeachCallback) error {
defer runtime.UnlockOSThread()
err := C._go_git_packbuilder_foreach(pb.ptr, handle)
runtime.KeepAlive(pb)
if err == C.GIT_EUSER {
return data.err
}
......
......@@ -47,6 +47,7 @@ func (patch *Patch) String() (string, error) {
var buf C.git_buf
ecode := C.git_patch_to_buf(&buf, patch.ptr)
runtime.KeepAlive(patch)
if ecode < 0 {
return "", MakeGitError(ecode)
}
......@@ -83,6 +84,8 @@ func (v *Repository) PatchFromBuffers(oldPath, newPath string, oldBuf, newBuf []
defer runtime.UnlockOSThread()
ecode := C.git_patch_from_buffers(&patchPtr, oldPtr, C.size_t(len(oldBuf)), cOldPath, newPtr, C.size_t(len(newBuf)), cNewPath, copts)
runtime.KeepAlive(oldBuf)
runtime.KeepAlive(newBuf)
if ecode < 0 {
return nil, MakeGitError(ecode)
}
......
......@@ -100,6 +100,7 @@ func mapEmptyStringToNull(ref string) *C.char {
// Rebase is the struct representing a Rebase object.
type Rebase struct {
ptr *C.git_rebase
r *Repository
}
// InitRebase initializes a rebase operation to rebase the changes in branch relative to upstream onto another branch.
......@@ -121,6 +122,9 @@ func (r *Repository) InitRebase(branch *AnnotatedCommit, upstream *AnnotatedComm
var ptr *C.git_rebase
err := C.git_rebase_init(&ptr, r.ptr, branch.ptr, upstream.ptr, onto.ptr, opts.toC())
runtime.KeepAlive(branch)
runtime.KeepAlive(upstream)
runtime.KeepAlive(onto)
if err < 0 {
return nil, MakeGitError(err)
}
......@@ -135,6 +139,7 @@ func (r *Repository) OpenRebase(opts *RebaseOptions) (*Rebase, error) {
var ptr *C.git_rebase
err := C.git_rebase_open(&ptr, r.ptr, opts.toC())
runtime.KeepAlive(r)
if err < 0 {
return nil, MakeGitError(err)
}
......@@ -145,7 +150,7 @@ func (r *Repository) OpenRebase(opts *RebaseOptions) (*Rebase, error) {
// OperationAt gets the rebase operation specified by the given index.
func (rebase *Rebase) OperationAt(index uint) *RebaseOperation {
operation := C.git_rebase_operation_byindex(rebase.ptr, C.size_t(index))
return newRebaseOperationFromC(operation)
}
......@@ -165,7 +170,9 @@ func (rebase *Rebase) CurrentOperationIndex() (uint, error) {
// OperationCount gets the count of rebase operations that are to be applied.
func (rebase *Rebase) OperationCount() uint {
return uint(C.git_rebase_operation_entrycount(rebase.ptr))
ret := uint(C.git_rebase_operation_entrycount(rebase.ptr))
runtime.KeepAlive(rebase)
return ret
}
// Next performs the next rebase operation and returns the information about it.
......@@ -178,6 +185,7 @@ func (rebase *Rebase) Next() (*RebaseOperation, error) {
var ptr *C.git_rebase_operation
err := C.git_rebase_next(&ptr, rebase.ptr)
runtime.KeepAlive(rebase)
if err < 0 {
return nil, MakeGitError(err)
}
......@@ -207,6 +215,8 @@ func (rebase *Rebase) Commit(ID *Oid, author, committer *Signature, message stri
defer C.free(unsafe.Pointer(cmsg))
cerr := C.git_rebase_commit(ID.toC(), rebase.ptr, authorSig, committerSig, nil, cmsg)
runtime.KeepAlive(ID)
runtime.KeepAlive(rebase)
if cerr < 0 {
return MakeGitError(cerr)
}
......@@ -220,6 +230,7 @@ func (rebase *Rebase) Finish() error {
defer runtime.UnlockOSThread()
err := C.git_rebase_finish(rebase.ptr, nil)
runtime.KeepAlive(rebase)
if err < 0 {
return MakeGitError(err)
}
......@@ -233,6 +244,7 @@ func (rebase *Rebase) Abort() error {
defer runtime.UnlockOSThread()
err := C.git_rebase_abort(rebase.ptr)
runtime.KeepAlive(rebase)
if err < 0 {
return MakeGitError(err)
}
......
......@@ -14,6 +14,7 @@ import (
type Refdb struct {
ptr *C.git_refdb
r *Repository
}
type RefdbBackend struct {
......@@ -21,16 +22,17 @@ type RefdbBackend struct {
}
func (v *Repository) NewRefdb() (refdb *Refdb, err error) {
refdb = new(Refdb)
var ptr *C.git_refdb
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_refdb_new(&refdb.ptr, v.ptr)
ret := C.git_refdb_new(&ptr, v.ptr)
if ret < 0 {
return nil, MakeGitError(ret)
}
refdb = &Refdb{ptr: ptr, r: v}
runtime.SetFinalizer(refdb, (*Refdb).Free)
return refdb, nil
}
......@@ -45,6 +47,8 @@ func (v *Refdb) SetBackend(backend *RefdbBackend) (err error) {
defer runtime.UnlockOSThread()
ret := C.git_refdb_set_backend(v.ptr, backend.ptr)
runtime.KeepAlive(v)
runtime.KeepAlive(backend)
if ret < 0 {
backend.Free()
return MakeGitError(ret)
......@@ -53,5 +57,6 @@ func (v *Refdb) SetBackend(backend *RefdbBackend) (err error) {
}
func (v *RefdbBackend) Free() {
runtime.SetFinalizer(v, nil)
C._go_git_refdb_backend_free(v.ptr)
}
......@@ -34,6 +34,7 @@ func (c *ReferenceCollection) Lookup(name string) (*Reference, error) {
defer runtime.UnlockOSThread()
ecode := C.git_reference_lookup(&ptr, c.repo.ptr, cname)
runtime.KeepAlive(c)
if ecode < 0 {
return nil, MakeGitError(ecode)
}
......@@ -59,6 +60,8 @@ func (c *ReferenceCollection) Create(name string, id *Oid, force bool, msg strin
defer runtime.UnlockOSThread()
ecode := C.git_reference_create(&ptr, c.repo.ptr, cname, id.toC(), cbool(force), cmsg)
runtime.KeepAlive(c)
runtime.KeepAlive(id)
if ecode < 0 {
return nil, MakeGitError(ecode)
}
......@@ -87,6 +90,7 @@ func (c *ReferenceCollection) CreateSymbolic(name, target string, force bool, ms
defer runtime.UnlockOSThread()
ecode := C.git_reference_symbolic_create(&ptr, c.repo.ptr, cname, ctarget, cbool(force), cmsg)
runtime.KeepAlive(c)
if ecode < 0 {
return nil, MakeGitError(ecode)
}
......@@ -104,6 +108,7 @@ func (c *ReferenceCollection) EnsureLog(name string) error {
defer runtime.UnlockOSThread()
ret := C.git_reference_ensure_log(c.repo.ptr, cname)
runtime.KeepAlive(c)
if ret < 0 {
return MakeGitError(ret)
}
......@@ -121,6 +126,7 @@ func (c *ReferenceCollection) HasLog(name string) (bool, error) {
defer runtime.UnlockOSThread()