blob: 578f43cc08f6c48887a0ecd8a2a45f8c7f52d0fd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
package git
/*
#include <git2.h>
#include <git2/sys/refdb_backend.h>
extern void _go_git_refdb_backend_free(git_refdb_backend *backend);
*/
import "C"
import (
"runtime"
"unsafe"
)
type Refdb struct {
ptr *C.git_refdb
r *Repository
}
type RefdbBackend struct {
ptr *C.git_refdb_backend
}
func (v *Repository) NewRefdb() (refdb *Refdb, err error) {
var ptr *C.git_refdb
runtime.LockOSThread()
defer runtime.UnlockOSThread()
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
}
func NewRefdbBackendFromC(ptr unsafe.Pointer) (backend *RefdbBackend) {
backend = &RefdbBackend{(*C.git_refdb_backend)(ptr)}
return backend
}
func (v *Refdb) SetBackend(backend *RefdbBackend) (err error) {
runtime.LockOSThread()
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)
}
return nil
}
func (v *RefdbBackend) Free() {
runtime.SetFinalizer(v, nil)
C._go_git_refdb_backend_free(v.ptr)
}
|