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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
// +build ignore
package main
import "C"
/*
//export c_Repository
func c_Repository() uint64 {
repo := &git.Repository{}
repo_handle := RegisterObject(repo)
return uint64(repo_handle)
}
//export c_NewRepository
func c_NewRepository(url string, auth uint64) (uint64, int, *C.char) {
var repo *git.Repository
var err error
url = CopyString(url)
if auth != IH {
real_auth, ok := GetObject(Handle(auth))
if !ok {
return IH, ErrorCodeNotFound, C.CString(MessageNotFound)
}
repo, err = git.NewRepository(url, real_auth.(common.AuthMethod))
} else {
repo, err = git.NewRepository(url, nil)
}
if err != nil {
return IH, ErrorCodeInternal, C.CString(err.Error())
}
repo_handle := RegisterObject(repo)
return uint64(repo_handle), ErrorCodeSuccess, nil
}
//export c_NewPlainRepository
func c_NewPlainRepository() uint64 {
return uint64(RegisterObject(git.NewPlainRepository()))
}
//export c_Repository_get_Remotes
func c_Repository_get_Remotes(r uint64) uint64 {
obj, ok := GetObject(Handle(r))
if !ok {
return IH
}
repo := obj.(*git.Repository)
return uint64(RegisterObject(&repo.Remotes))
}
//export c_Repository_set_Remotes
func c_Repository_set_Remotes(r uint64, val uint64) {
obj, ok := GetObject(Handle(r))
if !ok {
return
}
repo := obj.(*git.Repository)
obj, ok = GetObject(Handle(val))
if !ok {
return
}
repo.Remotes = *obj.(*map[string]*git.Remote)
}
//export c_Repository_get_Storage
func c_Repository_get_Storage(r uint64) uint64 {
obj, ok := GetObject(Handle(r))
if !ok {
return IH
}
repo := obj.(*git.Repository)
return uint64(RegisterObject(&repo.Storage))
}
//export c_Repository_set_Storage
func c_Repository_set_Storage(r uint64, val uint64) {
obj, ok := GetObject(Handle(r))
if !ok {
return
}
repo := obj.(*git.Repository)
obj, ok = GetObject(Handle(val))
if !ok {
return
}
repo.Storage = *obj.(*plumbing.ObjectStorage)
}
//export c_Repository_Pull
func c_Repository_Pull(r uint64, remoteName, branch string) (int, *C.char) {
obj, ok := GetObject(Handle(r))
if !ok {
return ErrorCodeNotFound, C.CString(MessageNotFound)
}
repo := obj.(*git.Repository)
err := repo.Pull(remoteName, CopyString(branch))
if err == nil {
return ErrorCodeSuccess, nil
}
return ErrorCodeInternal, C.CString(err.Error())
}
//export c_Repository_PullDefault
func c_Repository_PullDefault(r uint64) (int, *C.char) {
obj, ok := GetObject(Handle(r))
if !ok {
return ErrorCodeNotFound, C.CString(MessageNotFound)
}
repo := obj.(*git.Repository)
err := repo.PullDefault()
if err == nil {
return ErrorCodeSuccess, nil
}
return ErrorCodeInternal, C.CString(err.Error())
}
//export c_Repository_Commit
func c_Repository_Commit(r uint64, h []byte) (uint64, int, *C.char) {
obj, ok := GetObject(Handle(r))
if !ok {
return IH, ErrorCodeNotFound, C.CString(MessageNotFound)
}
repo := obj.(*git.Repository)
var hash plumbing.Hash
copy(hash[:], h)
commit, err := repo.Commit(hash)
if err != nil {
return IH, ErrorCodeInternal, C.CString(err.Error())
}
commit_handle := RegisterObject(commit)
return uint64(commit_handle), ErrorCodeSuccess, nil
}
//export c_Repository_Commits
func c_Repository_Commits(r uint64) (uint64, int, *C.char) {
obj, ok := GetObject(Handle(r))
if !ok {
return IH, ErrorCodeNotFound, C.CString(MessageNotFound)
}
repo := obj.(*git.Repository)
iter, err := repo.Commits()
if err != nil {
return IH, ErrorCodeInternal, C.CString(err.Error())
}
iter_handle := RegisterObject(iter)
return uint64(iter_handle), ErrorCodeSuccess, nil
}
//export c_Repository_Tree
func c_Repository_Tree(r uint64, h []byte) (uint64, int, *C.char) {
obj, ok := GetObject(Handle(r))
if !ok {
return IH, ErrorCodeNotFound, C.CString(MessageNotFound)
}
repo := obj.(*git.Repository)
var hash plumbing.Hash
copy(hash[:], h)
tree, err := repo.Tree(hash)
if err != nil {
return IH, ErrorCodeInternal, C.CString(err.Error())
}
tree_handle := RegisterObject(tree)
return uint64(tree_handle), ErrorCodeSuccess, nil
}
//export c_Repository_Blob
func c_Repository_Blob(r uint64, h []byte) (uint64, int, *C.char) {
obj, ok := GetObject(Handle(r))
if !ok {
return IH, ErrorCodeNotFound, C.CString(MessageNotFound)
}
repo := obj.(*git.Repository)
var hash plumbing.Hash
copy(hash[:], h)
blob, err := repo.Blob(hash)
if err != nil {
return IH, ErrorCodeInternal, C.CString(err.Error())
}
blob_handle := RegisterObject(blob)
return uint64(blob_handle), ErrorCodeSuccess, nil
}
//export c_Repository_Tag
func c_Repository_Tag(r uint64, h []byte) (uint64, int, *C.char) {
obj, ok := GetObject(Handle(r))
if !ok {
return IH, ErrorCodeNotFound, C.CString(MessageNotFound)
}
repo := obj.(*git.Repository)
var hash plumbing.Hash
copy(hash[:], h)
tag, err := repo.Tag(hash)
if err != nil {
return IH, ErrorCodeInternal, C.CString(err.Error())
}
tag_handle := RegisterObject(tag)
return uint64(tag_handle), ErrorCodeSuccess, nil
}
//export c_Repository_Tags
func c_Repository_Tags(r uint64) (uint64, int, *C.char) {
obj, ok := GetObject(Handle(r))
if !ok {
return IH, ErrorCodeNotFound, C.CString(MessageNotFound)
}
repo := obj.(*git.Repository)
iter, err := repo.Tags()
if err != nil {
return IH, ErrorCodeInternal, C.CString(err.Error())
}
iter_handle := RegisterObject(iter)
return uint64(iter_handle), ErrorCodeSuccess, nil
}
//export c_Repository_Object
func c_Repository_Object(r uint64, h []byte) (uint64, int, *C.char) {
obj, ok := GetObject(Handle(r))
if !ok {
return IH, ErrorCodeNotFound, C.CString(MessageNotFound)
}
repo := obj.(*git.Repository)
var hash plumbing.Hash
copy(hash[:], h)
robj, err := repo.Object(hash)
if err != nil {
return IH, ErrorCodeInternal, C.CString(err.Error())
}
robj_handle := RegisterObject(robj)
return uint64(robj_handle), ErrorCodeSuccess, nil
}
*/
|