1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
// +build ignore
package main
import (
"C"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/core"
)
//export c_Tree_get_Entries_len
func c_Tree_get_Entries_len(t uint64) int {
obj, ok := GetObject(Handle(t))
if !ok {
return 0
}
tree := obj.(*git.Tree)
return len(tree.Entries)
}
//export c_Tree_get_Entries_item
func c_Tree_get_Entries_item(t uint64, index int) (*C.char, uint32, *C.char) {
obj, ok := GetObject(Handle(t))
if !ok {
return nil, 0, nil
}
tree := obj.(*git.Tree)
item := tree.Entries[index]
return C.CString(item.Name), uint32(item.Mode), CBytes(item.Hash[:])
}
//export c_Tree_get_Hash
func c_Tree_get_Hash(t uint64) *C.char {
obj, ok := GetObject(Handle(t))
if !ok {
return nil
}
tree := obj.(*git.Tree)
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 {
return IH, ErrorCodeNotFound, C.CString(MessageNotFound)
}
tree := obj.(*git.Tree)
file, err := tree.File(CopyString(path))
if err != nil {
return IH, ErrorCodeInternal, C.CString(err.Error())
}
return uint64(RegisterObject(file)), ErrorCodeSuccess, nil
}
//export c_Tree_Type
func c_Tree_Type(t uint64) int8 {
obj, ok := GetObject(Handle(t))
if !ok {
return -1
}
tree := obj.(*git.Tree)
return int8(tree.Type())
}
//export c_Tree_Files
func c_Tree_Files(t uint64) uint64 {
obj, ok := GetObject(Handle(t))
if !ok {
return IH
}
tree := obj.(*git.Tree)
iter := tree.Files()
return uint64(RegisterObject(iter))
}
//export c_Tree_Decode
func c_Tree_Decode(o uint64) (uint64, int, *C.char) {
obj, ok := GetObject(Handle(o))
if !ok {
return IH, ErrorCodeNotFound, C.CString(MessageNotFound)
}
cobj := obj.(*core.Object)
tree := git.Tree{}
err := tree.Decode(*cobj)
if err != nil {
return IH, ErrorCodeInternal, C.CString(err.Error())
}
return uint64(RegisterObject(&tree)), ErrorCodeSuccess, nil
}
//export c_NewTreeWalker
func c_NewTreeWalker(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)
walker := git.NewTreeWalker(repo, tree)
return uint64(RegisterObject(walker))
}
//export c_TreeWalker_Next
func c_TreeWalker_Next(tw uint64) (*C.char, *C.char, uint32, *C.char,
uint64, int, *C.char) {
obj, ok := GetObject(Handle(tw))
if !ok {
return nil, nil, 0, nil, IH, ErrorCodeNotFound, C.CString(MessageNotFound)
}
walker := obj.(*git.TreeWalker)
name, entry, object, err := walker.Next()
if err != nil {
return nil, nil, 0, nil, IH, ErrorCodeInternal, C.CString(err.Error())
}
return C.CString(name), C.CString(entry.Name), uint32(entry.Mode),
CBytes(entry.Hash[:]), uint64(RegisterObject(&object)),
ErrorCodeSuccess, nil
}
//export c_TreeWalker_Tree
func c_TreeWalker_Tree(tw uint64) uint64 {
obj, ok := GetObject(Handle(tw))
if !ok {
return IH
}
walker := obj.(*git.TreeWalker)
return uint64(RegisterObject(walker.Tree()))
}
//export c_TreeWalker_Close
func c_TreeWalker_Close(tw uint64) {
obj, ok := GetObject(Handle(tw))
if !ok {
return
}
walker := obj.(*git.TreeWalker)
walker.Close()
}
|