aboutsummaryrefslogtreecommitdiffstats
path: root/cshared/commit_cshared.go
diff options
context:
space:
mode:
authorVadim Markovtsev <vadim@sourced.tech>2016-06-21 17:14:53 +0300
committerVadim Markovtsev <vadim@sourced.tech>2016-06-21 17:14:53 +0300
commitda07dca4523ebd25c634152a62cae4a72eb5783f (patch)
tree028122b562ce464ae4410525b5b3d3dfcea4846c /cshared/commit_cshared.go
parentbea415417e87fbb403095e8cd3fb8512a1a97af8 (diff)
downloadgo-git-da07dca4523ebd25c634152a62cae4a72eb5783f.tar.gz
Wrap more objects with CGo
Diffstat (limited to 'cshared/commit_cshared.go')
-rw-r--r--cshared/commit_cshared.go41
1 files changed, 40 insertions, 1 deletions
diff --git a/cshared/commit_cshared.go b/cshared/commit_cshared.go
index 791660b..51b2c1a 100644
--- a/cshared/commit_cshared.go
+++ b/cshared/commit_cshared.go
@@ -4,6 +4,8 @@ package main
import (
"C"
"io"
+ "reflect"
+ "unsafe"
"gopkg.in/src-d/go-git.v3"
"gopkg.in/src-d/go-git.v3/core"
@@ -16,7 +18,7 @@ func c_Commit_get_Hash(c uint64) *C.char {
return nil
}
commit := obj.(*git.Commit)
- return C.CString(string(commit.Hash[:]))
+ return CBytes(commit.Hash[:])
}
//export c_Commit_get_Author
@@ -142,6 +144,43 @@ func c_Commit_String(c uint64) *C.char {
return C.CString(commit.String())
}
+//export c_Commit_References
+func c_Commit_References(c uint64, path string) (*C.char, int, int, *C.char) {
+ obj, ok := GetObject(Handle(c))
+ if !ok {
+ return nil, 0, ErrorCodeNotFound, C.CString(MessageNotFound)
+ }
+ commit := obj.(*git.Commit)
+ refs, err := commit.References(CopyString(path))
+ if err != nil {
+ return nil, 0, ErrorCodeInternal, C.CString(err.Error())
+ }
+ handles := make([]uint64, len(refs))
+ for i, c := range(refs) {
+ handles[i] = uint64(RegisterObject(c))
+ }
+ size := 8 * len(handles)
+ dest := C.malloc(C.size_t(size))
+ header := (*reflect.SliceHeader)(unsafe.Pointer(&handles))
+ header.Len *= 8
+ copy((*[1<<30]byte)(dest)[:], *(*[]byte)(unsafe.Pointer(header)))
+ return (*C.char)(dest), size / 8, ErrorCodeSuccess, nil
+}
+
+//export c_Commit_Blame
+func c_Commit_Blame(c uint64, path string) (uint64, int, *C.char) {
+ obj, ok := GetObject(Handle(c))
+ if !ok {
+ return IH, ErrorCodeNotFound, C.CString(MessageNotFound)
+ }
+ commit := obj.(*git.Commit)
+ blame, err := commit.Blame(CopyString(path))
+ if err != nil {
+ return IH, ErrorCodeInternal, C.CString(err.Error())
+ }
+ return uint64(RegisterObject(blame)), ErrorCodeSuccess, nil
+}
+
//export c_NewCommitIter
func c_NewCommitIter(r uint64, iter uint64) uint64 {
obj, ok := GetObject(Handle(r))