@@ -4,6 +4,8 @@ package main
44import (
55 "C"
66 "io"
7+ "reflect"
8+ "unsafe"
79
810 "gopkg.in/src-d/go-git.v3"
911 "gopkg.in/src-d/go-git.v3/core"
@@ -16,7 +18,7 @@ func c_Commit_get_Hash(c uint64) *C.char {
1618 return nil
1719 }
1820 commit := obj .(* git.Commit )
19- return C . CString ( string ( commit .Hash [:]) )
21+ return CBytes ( commit .Hash [:])
2022}
2123
2224//export c_Commit_get_Author
@@ -142,6 +144,43 @@ func c_Commit_String(c uint64) *C.char {
142144 return C .CString (commit .String ())
143145}
144146
147+ //export c_Commit_References
148+ func c_Commit_References (c uint64 , path string ) (* C.char , int , int , * C.char ) {
149+ obj , ok := GetObject (Handle (c ))
150+ if ! ok {
151+ return nil , 0 , ErrorCodeNotFound , C .CString (MessageNotFound )
152+ }
153+ commit := obj .(* git.Commit )
154+ refs , err := commit .References (CopyString (path ))
155+ if err != nil {
156+ return nil , 0 , ErrorCodeInternal , C .CString (err .Error ())
157+ }
158+ handles := make ([]uint64 , len (refs ))
159+ for i , c := range (refs ) {
160+ handles [i ] = uint64 (RegisterObject (c ))
161+ }
162+ size := 8 * len (handles )
163+ dest := C .malloc (C .size_t (size ))
164+ header := (* reflect .SliceHeader )(unsafe .Pointer (& handles ))
165+ header .Len *= 8
166+ copy ((* [1 << 30 ]byte )(dest )[:], * (* []byte )(unsafe .Pointer (header )))
167+ return (* C .char )(dest ), size / 8 , ErrorCodeSuccess , nil
168+ }
169+
170+ //export c_Commit_Blame
171+ func c_Commit_Blame (c uint64 , path string ) (uint64 , int , * C.char ) {
172+ obj , ok := GetObject (Handle (c ))
173+ if ! ok {
174+ return IH , ErrorCodeNotFound , C .CString (MessageNotFound )
175+ }
176+ commit := obj .(* git.Commit )
177+ blame , err := commit .Blame (CopyString (path ))
178+ if err != nil {
179+ return IH , ErrorCodeInternal , C .CString (err .Error ())
180+ }
181+ return uint64 (RegisterObject (blame )), ErrorCodeSuccess , nil
182+ }
183+
145184//export c_NewCommitIter
146185func c_NewCommitIter (r uint64 , iter uint64 ) uint64 {
147186 obj , ok := GetObject (Handle (r ))
0 commit comments