diff options
author | Vadim Markovtsev <vadim@sourced.tech> | 2016-06-21 17:14:53 +0300 |
---|---|---|
committer | Vadim Markovtsev <vadim@sourced.tech> | 2016-06-21 17:14:53 +0300 |
commit | da07dca4523ebd25c634152a62cae4a72eb5783f (patch) | |
tree | 028122b562ce464ae4410525b5b3d3dfcea4846c /cshared/file_cshared.go | |
parent | bea415417e87fbb403095e8cd3fb8512a1a97af8 (diff) | |
download | go-git-da07dca4523ebd25c634152a62cae4a72eb5783f.tar.gz |
Wrap more objects with CGo
Diffstat (limited to 'cshared/file_cshared.go')
-rw-r--r-- | cshared/file_cshared.go | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/cshared/file_cshared.go b/cshared/file_cshared.go new file mode 100644 index 0000000..7f7c917 --- /dev/null +++ b/cshared/file_cshared.go @@ -0,0 +1,67 @@ +package main + +import ( + "C" + + "gopkg.in/src-d/go-git.v3" +) + +//export c_File_get_Name +func c_File_get_Name(f uint64) *C.char { + obj, ok := GetObject(Handle(f)) + if !ok { + return nil + } + file := obj.(*git.File) + return C.CString(file.Name) +} + +//export c_File_get_Mode +func c_File_get_Mode(f uint64) uint32 { + obj, ok := GetObject(Handle(f)) + if !ok { + return 0 + } + file := obj.(*git.File) + return uint32(file.Mode) +} + +//export c_NewFileIter +func c_NewFileIter(r uint64, t uint64) uint64 { + obj, ok := GetObject(Handle(r)) + if !ok { + return IH + } + repo := obj.(*git.Repository) + obj, ok = GetObject(Handle(t)) + if !ok { + return IH + } + tree := obj.(*git.Tree) + iter := git.NewFileIter(repo, tree) + return uint64(RegisterObject(iter)) +} + +//export c_FileIter_Next +func c_FileIter_Next(i uint64) (uint64, int, *C.char) { + obj, ok := GetObject(Handle(i)) + if !ok { + return IH, ErrorCodeNotFound, C.CString(MessageNotFound) + } + iter := obj.(*git.FileIter) + file, err := iter.Next() + if err != nil { + return IH, ErrorCodeInternal, C.CString(err.Error()) + } + return uint64(RegisterObject(file)), ErrorCodeSuccess, nil +} + +//export c_FileIter_Close +func c_FileIter_Close(i uint64) { + obj, ok := GetObject(Handle(i)) + if !ok { + return + } + iter := obj.(*git.FileIter) + iter.Close() +} |