Remote: add support for transfer and update_tips though CFFI

This commit is contained in:
Carlos Martín Nieto
2014-04-12 17:33:15 +02:00
parent 4ef3be18cc
commit 2d1615dd29
2 changed files with 45 additions and 1 deletions

View File

@@ -3,7 +3,12 @@ typedef ... git_remote;
typedef ... git_refspec;
typedef ... git_push;
typedef ... git_cred;
typedef ... git_oid;
#define GIT_OID_RAWSZ ...
typedef struct git_oid {
unsigned char id[20];
} git_oid;
typedef struct git_strarray {
char **strings;

View File

@@ -28,6 +28,8 @@
# Import from the future
from __future__ import absolute_import
from _pygit2 import Oid
from .ffi import ffi, C, to_str, strarray_to_strings, strings_to_strarray
from .errors import check_error, GitError
from .refspec import Refspec
@@ -62,7 +64,9 @@ class Remote(object):
# Build the callback structure
callbacks = ffi.new('git_remote_callbacks *')
callbacks.version = 1
callbacks.progress = self._progress_cb
callbacks.transfer_progress = self._transfer_progress_cb
callbacks.update_tips = self._update_tips_cb
callbacks.credentials = self._credentials_cb
# We need to make sure that this handle stays alive
self._self_handle = ffi.new_handle(self)
@@ -209,6 +213,41 @@ class Remote(object):
return 0
@ffi.callback('int (*progress)(const char *str, int len, void *data)')
def _progress_cb(string, length, data):
self = ffi.from_handle(data)
if not hasattr(self, 'progress'):
return 0
try:
s = ffi.string(string, length).decode()
self.progress(s)
except Exception, e:
self._stored_exception = e
return C.GIT_EUSER
return 0
@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)
if not hasattr(self, 'update_tips'):
return 0
try:
s = maybe_string(refname)
a = Oid(raw=bytes(ffi.buffer(a)))
b = Oid(raw=bytes(ffi.buffer(b)))
self.update_tips(s, a, b)
except Exception, e:
self._stored_exception = e
return C.GIT_EUSER
return 0
@ffi.callback('int (*credentials)(git_cred **cred, const char *url, const char *username_from_url, unsigned int allowed_types, void *data)')
def _credentials_cb(cred_out, url, username, allowed, data):
self = ffi.from_handle(data)