55
55
# function, or raises exception from libgit2 error
56
56
#
57
57
58
+ class Payload :
59
+
60
+ def __init__ (self , ** kw ):
61
+ for key , value in kw .items ():
62
+ setattr (self , key , value )
63
+ self ._stored_exception = None
64
+
65
+ def check_error (self ):
66
+ if self ._stored_exception is not None :
67
+ raise self ._stored_exception
68
+
69
+
70
+ @contextmanager
71
+ def git_clone_options (payload , opts = None ):
72
+ if opts is None :
73
+ opts = ffi .new ('git_clone_options *' )
74
+ C .git_clone_options_init (opts , C .GIT_CLONE_OPTIONS_VERSION )
75
+
76
+ handle = ffi .new_handle (payload )
77
+
78
+ # Plug callbacks
79
+ if payload .repository :
80
+ opts .repository_cb = C ._repository_create_cb
81
+ opts .repository_cb_payload = handle
82
+ if payload .remote :
83
+ opts .remote_cb = C ._remote_create_cb
84
+ opts .remote_cb_payload = handle
85
+
86
+ # Give back control
87
+ yield opts , payload
88
+
89
+
58
90
@contextmanager
59
91
def git_fetch_options (callbacks , opts = None ):
60
92
if callbacks is None :
@@ -153,16 +185,15 @@ def wrapper(*args):
153
185
data ._stored_exception = e
154
186
return C .GIT_EUSER
155
187
156
- return wrapper
188
+ return ffi . def_extern ()( wrapper )
157
189
158
190
159
- @ffi .def_extern ()
160
191
@callback_proxy
161
192
def _certificate_cb (cert_i , valid , host , data ):
162
- # We want to simulate what should happen if libgit2 supported pass-through for
163
- # this callback. For SSH, 'valid' is always False, because it doesn't look
164
- # at known_hosts, but we do want to let it through in order to do what libgit2 would
165
- # if the callback were not set.
193
+ # We want to simulate what should happen if libgit2 supported pass-through
194
+ # for this callback. For SSH, 'valid' is always False, because it doesn't
195
+ # look at known_hosts, but we do want to let it through in order to do what
196
+ # libgit2 would if the callback were not set.
166
197
try :
167
198
is_ssh = cert_i .cert_type == C .GIT_CERT_HOSTKEY_LIBSSH2
168
199
@@ -185,7 +216,6 @@ def _certificate_cb(cert_i, valid, host, data):
185
216
return 0
186
217
187
218
188
- @ffi .def_extern ()
189
219
@callback_proxy
190
220
def _credentials_cb (cred_out , url , username , allowed , data ):
191
221
credentials = getattr (data , 'credentials' , None )
@@ -197,7 +227,6 @@ def _credentials_cb(cred_out, url, username, allowed, data):
197
227
return 0
198
228
199
229
200
- @ffi .def_extern ()
201
230
@callback_proxy
202
231
def _push_update_reference_cb (ref , msg , data ):
203
232
push_update_reference = getattr (data , 'push_update_reference' , None )
@@ -210,7 +239,28 @@ def _push_update_reference_cb(ref, msg, data):
210
239
return 0
211
240
212
241
213
- @ffi .def_extern ()
242
+ @callback_proxy
243
+ def _remote_create_cb (remote_out , repo , name , url , data ):
244
+ from .repository import Repository
245
+
246
+ remote = data .remote (Repository ._from_c (repo , False ), ffi .string (name ), ffi .string (url ))
247
+ remote_out [0 ] = remote ._remote
248
+ # we no longer own the C object
249
+ remote ._remote = ffi .NULL
250
+
251
+ return 0
252
+
253
+
254
+ @callback_proxy
255
+ def _repository_create_cb (repo_out , path , bare , data ):
256
+ repository = data .repository (ffi .string (path ), bare != 0 )
257
+ # we no longer own the C object
258
+ repository ._disown ()
259
+ repo_out [0 ] = repository ._repo
260
+
261
+ return 0
262
+
263
+
214
264
@callback_proxy
215
265
def _sideband_progress_cb (string , length , data ):
216
266
progress = getattr (data , 'progress' , None )
@@ -222,7 +272,6 @@ def _sideband_progress_cb(string, length, data):
222
272
return 0
223
273
224
274
225
- @ffi .def_extern ()
226
275
@callback_proxy
227
276
def _transfer_progress_cb (stats_ptr , data ):
228
277
from .remote import TransferProgress
@@ -235,7 +284,6 @@ def _transfer_progress_cb(stats_ptr, data):
235
284
return 0
236
285
237
286
238
- @ffi .def_extern ()
239
287
@callback_proxy
240
288
def _update_tips_cb (refname , a , b , data ):
241
289
update_tips = getattr (data , 'update_tips' , None )
0 commit comments