Skip to content

Commit

Permalink
cffi callbacks written shorter
Browse files Browse the repository at this point in the history
If the callback is defined with a typedef in decl, don't need to write
again the signature in Python, just the name.
  • Loading branch information
jdavid committed Apr 13, 2019
1 parent 285fca3 commit c43db44
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
5 changes: 2 additions & 3 deletions pygit2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def init_repository(path, bare=False,
# Ok
return Repository(to_str(path))

@ffi.callback('int (*cb)(git_repository **out, const char *path, int bare, void *payload)')
@ffi.callback('git_repository_create_cb')
def _repository_create_cb(repo_out, path, bare, data):
d = ffi.from_handle(data)
try:
Expand All @@ -167,8 +167,7 @@ def _repository_create_cb(repo_out, path, bare, data):

return 0

@ffi.callback('int (*cb)(git_remote **out, git_repository *repo,'
'const char *name, const char *url, void *payload)')
@ffi.callback('git_remote_create_cb')
def _remote_create_cb(remote_out, repo, name, url, data):
d = ffi.from_handle(data)
try:
Expand Down
13 changes: 6 additions & 7 deletions pygit2/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,9 @@ def _sideband_progress_cb(string, length, data):

return 0

@ffi.callback('int (*update_tips)(const char *refname, const git_oid *a,'
'const git_oid *b, void *data)')
@ffi.callback(
'int (*update_tips)(const char *refname, const git_oid *a, const git_oid *b, void *data)'
)
def _update_tips_cb(refname, a, b, data):
self = ffi.from_handle(data)

Expand All @@ -273,7 +274,7 @@ def _update_tips_cb(refname, a, b, data):

return 0

@ffi.callback("int (*push_update_reference)(const char *ref, const char *msg, void *data)")
@ffi.callback('git_push_update_reference_cb')
def _push_update_reference_cb(ref, msg, data):
self = ffi.from_handle(data)

Expand All @@ -291,9 +292,7 @@ def _push_update_reference_cb(ref, msg, data):

return 0

@ffi.callback('int (*cb)(git_cred **cred, const char *url,'
'const char *username_from_url, unsigned int allowed_types,'
'void *data)')
@ffi.callback('git_cred_acquire_cb')
def _credentials_cb(cred_out, url, username, allowed, data):
self = ffi.from_handle(data)

Expand All @@ -312,7 +311,7 @@ def _credentials_cb(cred_out, url, username, allowed, data):

return 0

@ffi.callback('int (*cb)(git_cert *cert, int valid, const char *host, void *payload)')
@ffi.callback('git_transport_certificate_check_cb')
def _certificate_cb(cert_i, valid, host, data):
self = ffi.from_handle(data)

Expand Down

0 comments on commit c43db44

Please sign in to comment.