Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit dc1e2bd

Browse files
vmarkovtsevmcuadros
authored andcommitted
Fix some bugs found during gypogit testing (#58)
1 parent 5e73f01 commit dc1e2bd

File tree

4 files changed

+83
-1
lines changed

4 files changed

+83
-1
lines changed

cshared/file_cshared.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package main
22

33
import (
44
"C"
5+
"io"
6+
"io/ioutil"
57

68
"gopkg.in/src-d/go-git.v3"
9+
"gopkg.in/src-d/go-git.v3/core"
710
)
811

912
//export c_File_get_Name
@@ -26,6 +29,67 @@ func c_File_get_Mode(f uint64) uint32 {
2629
return uint32(file.Mode)
2730
}
2831

32+
//export c_File_get_Hash
33+
func c_File_get_Hash(b uint64) *C.char {
34+
obj, ok := GetObject(Handle(b))
35+
if !ok {
36+
return nil
37+
}
38+
file := obj.(*git.File)
39+
return CBytes(file.Hash[:])
40+
}
41+
42+
//export c_File_Size
43+
func c_File_Size(b uint64) int64 {
44+
obj, ok := GetObject(Handle(b))
45+
if !ok {
46+
return -1
47+
}
48+
file := obj.(*git.File)
49+
return file.Size
50+
}
51+
52+
//export c_File_Decode
53+
func c_File_Decode(o uint64) uint64 {
54+
obj, ok := GetObject(Handle(o))
55+
if !ok {
56+
return IH
57+
}
58+
cobj := obj.(*core.Object)
59+
file := git.File{}
60+
file.Decode(*cobj)
61+
return uint64(RegisterObject(&file))
62+
}
63+
64+
//export c_File_Read
65+
func c_File_Read(b uint64) (int, *C.char) {
66+
obj, ok := GetObject(Handle(b))
67+
if !ok {
68+
return ErrorCodeNotFound, C.CString(MessageNotFound)
69+
}
70+
file := obj.(*git.File)
71+
reader, err := file.Reader()
72+
if err != nil {
73+
return ErrorCodeInternal, C.CString(err.Error())
74+
}
75+
data, err := ioutil.ReadAll(reader)
76+
reader.Close()
77+
if err != nil {
78+
return ErrorCodeInternal, C.CString(err.Error())
79+
}
80+
return len(data), CBytes(data)
81+
}
82+
83+
//export c_File_Type
84+
func c_File_Type(c uint64) int8 {
85+
obj, ok := GetObject(Handle(c))
86+
if !ok {
87+
return -1
88+
}
89+
file := obj.(*git.File)
90+
return int8(file.Type())
91+
}
92+
2993
//export c_NewFileIter
3094
func c_NewFileIter(r uint64, t uint64) uint64 {
3195
obj, ok := GetObject(Handle(r))
@@ -51,6 +115,9 @@ func c_FileIter_Next(i uint64) (uint64, int, *C.char) {
51115
iter := obj.(*git.FileIter)
52116
file, err := iter.Next()
53117
if err != nil {
118+
if err == io.EOF {
119+
return IH, ErrorCodeSuccess, nil
120+
}
54121
return IH, ErrorCodeInternal, C.CString(err.Error())
55122
}
56123
return uint64(RegisterObject(file)), ErrorCodeSuccess, nil

cshared/objects_cshared.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,15 @@ func c_Blob_Read(b uint64) (int, *C.char) {
9595
if err != nil {
9696
return ErrorCodeInternal, C.CString(err.Error())
9797
}
98-
return len(data), C.CString(string(data))
98+
return len(data), CBytes(data)
99+
}
100+
101+
//export c_Blob_Type
102+
func c_Blob_Type(c uint64) int8 {
103+
obj, ok := GetObject(Handle(c))
104+
if !ok {
105+
return -1
106+
}
107+
blob := obj.(*git.Blob)
108+
return int8(blob.Type())
99109
}

cshared/tag_cshared.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33

44
import (
55
"C"
6+
"io"
67

78
"gopkg.in/src-d/go-git.v3"
89
"gopkg.in/src-d/go-git.v3/core"
@@ -177,6 +178,9 @@ func c_TagIter_Next(i uint64) (uint64, int, *C.char) {
177178
tagiter := obj.(*git.TagIter)
178179
tag, err := tagiter.Next()
179180
if err != nil {
181+
if err == io.EOF {
182+
return IH, ErrorCodeSuccess, nil
183+
}
180184
return IH, ErrorCodeInternal, C.CString(err.Error())
181185
}
182186
return uint64(RegisterObject(tag)), ErrorCodeSuccess, nil

cshared/tree_cshared.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func c_Tree_get_Hash(t uint64) *C.char {
3939
return CBytes(tree.Hash[:])
4040
}
4141

42+
//export c_Tree_File
4243
func c_Tree_File(t uint64, path string) (uint64, int, *C.char) {
4344
obj, ok := GetObject(Handle(t))
4445
if !ok {

0 commit comments

Comments
 (0)