Skip to content

Commit c3b7870

Browse files
committed
Internal: Refactor callbacks code
Last clean-ups and internal documentaion.
1 parent 6e18deb commit c3b7870

File tree

5 files changed

+236
-198
lines changed

5 files changed

+236
-198
lines changed

pygit2/__init__.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -192,22 +192,26 @@ def clone_repository(
192192
`pyclass:RemoteCallbacks`.
193193
"""
194194

195-
# Initialize payload
196-
payload = Payload(repository=repository, remote=remote)
195+
if callbacks is None:
196+
callbacks = RemoteCallbacks()
197197

198-
with git_clone_options(payload) as (opts, _):
198+
# Add repository and remote to the payload
199+
payload = callbacks
200+
payload.repository = repository
201+
payload.remote = remote
202+
203+
with git_clone_options(payload):
204+
opts = payload.clone_options
199205
opts.bare = bare
200206

201-
#checkout_branch_ref = None
202207
if checkout_branch:
203208
checkout_branch_ref = ffi.new('char []', to_bytes(checkout_branch))
204209
opts.checkout_branch = checkout_branch_ref
205210

206-
with git_fetch_options(callbacks, opts=opts.fetch_opts) as (_, cb):
211+
with git_fetch_options(payload, opts=opts.fetch_opts):
207212
crepo = ffi.new('git_repository **')
208213
err = C.git_clone(crepo, to_bytes(url), to_bytes(path), opts)
209-
payload.check_error()
210-
check_error(err, cb)
214+
payload.check_error(err)
211215

212216
# Ok
213217
return Repository._from_c(crepo[0], owned=True)

0 commit comments

Comments
 (0)