aboutsummaryrefslogtreecommitdiffstats
path: root/cshared
diff options
context:
space:
mode:
authorVadim Markovtsev <gmarkhor@gmail.com>2016-07-09 01:16:13 +0300
committerMáximo Cuadros <mcuadros@gmail.com>2016-07-09 00:16:13 +0200
commitdc1e2bd485f8345c14cf7b22a5b71fd03028cfdf (patch)
treee8069982be7c0d7e9334b032579c5767f9f09e8f /cshared
parent5e73f01cb2e027a8f02801635b79d3a9bc866914 (diff)
downloadgo-git-dc1e2bd485f8345c14cf7b22a5b71fd03028cfdf.tar.gz
Fix some bugs found during gypogit testing (#58)
Diffstat (limited to 'cshared')
-rw-r--r--cshared/file_cshared.go67
-rw-r--r--cshared/objects_cshared.go12
-rw-r--r--cshared/tag_cshared.go4
-rw-r--r--cshared/tree_cshared.go1
4 files changed, 83 insertions, 1 deletions
diff --git a/cshared/file_cshared.go b/cshared/file_cshared.go
index 7f7c917..635b853 100644
--- a/cshared/file_cshared.go
+++ b/cshared/file_cshared.go
@@ -2,8 +2,11 @@ package main
import (
"C"
+ "io"
+ "io/ioutil"
"gopkg.in/src-d/go-git.v3"
+ "gopkg.in/src-d/go-git.v3/core"
)
//export c_File_get_Name
@@ -26,6 +29,67 @@ func c_File_get_Mode(f uint64) uint32 {
return uint32(file.Mode)
}
+//export c_File_get_Hash
+func c_File_get_Hash(b uint64) *C.char {
+ obj, ok := GetObject(Handle(b))
+ if !ok {
+ return nil
+ }
+ file := obj.(*git.File)
+ return CBytes(file.Hash[:])
+}
+
+//export c_File_Size
+func c_File_Size(b uint64) int64 {
+ obj, ok := GetObject(Handle(b))
+ if !ok {
+ return -1
+ }
+ file := obj.(*git.File)
+ return file.Size
+}
+
+//export c_File_Decode
+func c_File_Decode(o uint64) uint64 {
+ obj, ok := GetObject(Handle(o))
+ if !ok {
+ return IH
+ }
+ cobj := obj.(*core.Object)
+ file := git.File{}
+ file.Decode(*cobj)
+ return uint64(RegisterObject(&file))
+}
+
+//export c_File_Read
+func c_File_Read(b uint64) (int, *C.char) {
+ obj, ok := GetObject(Handle(b))
+ if !ok {
+ return ErrorCodeNotFound, C.CString(MessageNotFound)
+ }
+ file := obj.(*git.File)
+ reader, err := file.Reader()
+ if err != nil {
+ return ErrorCodeInternal, C.CString(err.Error())
+ }
+ data, err := ioutil.ReadAll(reader)
+ reader.Close()
+ if err != nil {
+ return ErrorCodeInternal, C.CString(err.Error())
+ }
+ return len(data), CBytes(data)
+}
+
+//export c_File_Type
+func c_File_Type(c uint64) int8 {
+ obj, ok := GetObject(Handle(c))
+ if !ok {
+ return -1
+ }
+ file := obj.(*git.File)
+ return int8(file.Type())
+}
+
//export c_NewFileIter
func c_NewFileIter(r uint64, t uint64) uint64 {
obj, ok := GetObject(Handle(r))
@@ -51,6 +115,9 @@ func c_FileIter_Next(i uint64) (uint64, int, *C.char) {
iter := obj.(*git.FileIter)
file, err := iter.Next()
if err != nil {
+ if err == io.EOF {
+ return IH, ErrorCodeSuccess, nil
+ }
return IH, ErrorCodeInternal, C.CString(err.Error())
}
return uint64(RegisterObject(file)), ErrorCodeSuccess, nil
diff --git a/cshared/objects_cshared.go b/cshared/objects_cshared.go
index 9f14598..68e7b4f 100644
--- a/cshared/objects_cshared.go
+++ b/cshared/objects_cshared.go
@@ -95,5 +95,15 @@ func c_Blob_Read(b uint64) (int, *C.char) {
if err != nil {
return ErrorCodeInternal, C.CString(err.Error())
}
- return len(data), C.CString(string(data))
+ return len(data), CBytes(data)
+}
+
+//export c_Blob_Type
+func c_Blob_Type(c uint64) int8 {
+ obj, ok := GetObject(Handle(c))
+ if !ok {
+ return -1
+ }
+ blob := obj.(*git.Blob)
+ return int8(blob.Type())
} \ No newline at end of file
diff --git a/cshared/tag_cshared.go b/cshared/tag_cshared.go
index 2a8db65..e188e2c 100644
--- a/cshared/tag_cshared.go
+++ b/cshared/tag_cshared.go
@@ -3,6 +3,7 @@ package main
import (
"C"
+ "io"
"gopkg.in/src-d/go-git.v3"
"gopkg.in/src-d/go-git.v3/core"
@@ -177,6 +178,9 @@ func c_TagIter_Next(i uint64) (uint64, int, *C.char) {
tagiter := obj.(*git.TagIter)
tag, err := tagiter.Next()
if err != nil {
+ if err == io.EOF {
+ return IH, ErrorCodeSuccess, nil
+ }
return IH, ErrorCodeInternal, C.CString(err.Error())
}
return uint64(RegisterObject(tag)), ErrorCodeSuccess, nil
diff --git a/cshared/tree_cshared.go b/cshared/tree_cshared.go
index 0d4191c..e1f3ae1 100644
--- a/cshared/tree_cshared.go
+++ b/cshared/tree_cshared.go
@@ -39,6 +39,7 @@ func c_Tree_get_Hash(t uint64) *C.char {
return CBytes(tree.Hash[:])
}
+//export c_Tree_File
func c_Tree_File(t uint64, path string) (uint64, int, *C.char) {
obj, ok := GetObject(Handle(t))
if !ok {