summaryrefslogtreecommitdiff
path: root/git.go
diff options
context:
space:
mode:
Diffstat (limited to 'git.go')
-rw-r--r--git.go24
1 files changed, 17 insertions, 7 deletions
diff --git a/git.go b/git.go
index c663d2e..72ea33e 100644
--- a/git.go
+++ b/git.go
@@ -9,8 +9,9 @@ import "C"
import (
"bytes"
"errors"
- "strings"
+ "runtime"
"unsafe"
+ "strings"
)
const (
@@ -57,6 +58,9 @@ func NewOidFromString(s string) (*Oid, error) {
cs := C.CString(s)
defer C.free(unsafe.Pointer(cs))
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
if C.git_oid_fromstr(o.toC(), cs) < 0 {
return nil, LastError()
}
@@ -109,6 +113,10 @@ func ShortenOids(ids []*Oid, minlen int) (int, error) {
defer C.git_oid_shorten_free(shorten)
var ret C.int
+
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
for _, id := range ids {
buf := make([]byte, 41)
C.git_oid_fmt((*C.char)(unsafe.Pointer(&buf[0])), id.toC())
@@ -159,14 +167,16 @@ func Discover(start string, across_fs bool, ceiling_dirs []string) (string, erro
cstart := C.CString(start)
defer C.free(unsafe.Pointer(cstart))
- retpath := (*C.git_buf)(C.malloc(C.GIT_PATH_MAX))
- defer C.git_buf_free(retpath)
+ var buf C.git_buf
+ defer C.git_buf_free(&buf)
- r := C.git_repository_discover(retpath, cstart, cbool(across_fs), ceildirs)
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
- if r == 0 {
- return C.GoString(retpath.ptr), nil
+ ret := C.git_repository_discover(&buf, cstart, cbool(across_fs), ceildirs)
+ if ret < 0 {
+ return "", LastError()
}
- return "", LastError()
+ return C.GoString(buf.ptr), nil
}