forked from libgit2/git2go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.go
67 lines (52 loc) · 1 KB
/
index.go
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
63
64
65
66
67
package git
/*
#include <git2.h>
#include <git2/errors.h>
*/
import "C"
import (
"runtime"
"unsafe"
)
type Index struct {
ptr *C.git_index
}
func newIndexFromC(ptr *C.git_index) *Index {
idx := &Index{ptr}
runtime.SetFinalizer(idx, (*Index).Free)
return idx
}
func (v *Index) AddByPath(path string) error {
cstr := C.CString(path)
defer C.free(unsafe.Pointer(cstr))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_index_add_bypath(v.ptr, cstr)
if ret < 0 {
return LastError()
}
return nil
}
func (v *Index) WriteTree() (*Oid, error) {
oid := new(Oid)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_index_write_tree(oid.toC(), v.ptr)
if ret < 0 {
return nil, LastError()
}
return oid, nil
}
func (v *Index) Write() (error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_index_write(v.ptr)
if ret < 0 {
return LastError()
}
return nil
}
func (v *Index) Free() {
runtime.SetFinalizer(v, nil)
C.git_index_free(v.ptr)
}