Add wrap remote.

This commit is contained in:
XTao
2014-01-29 15:14:57 +08:00
parent 94e841bfb2
commit 5b4b7f39d5
3 changed files with 27 additions and 14 deletions

View File

@@ -1036,7 +1036,7 @@ PyMemberDef Remote_members[] = {
MEMBER(Remote, progress, T_OBJECT_EX, "Progress output callback"),
MEMBER(Remote, transfer_progress, T_OBJECT_EX, "Transfer progress callback"),
MEMBER(Remote, update_tips, T_OBJECT_EX, "update tips callback"),
{NULL},
{NULL},
};
PyDoc_STRVAR(Remote__doc__, "Remote object.");
@@ -1081,3 +1081,21 @@ PyTypeObject RemoteType = {
0, /* tp_alloc */
0, /* tp_new */
};
PyObject *
wrap_remote(git_remote *c_remote, Repository *repo)
{
Remote *py_remote = NULL;
py_remote = PyObject_New(Remote, &RemoteType);
if (py_remote) {
Py_INCREF(repo);
py_remote->repo = repo;
py_remote->remote = c_remote;
py_remote->progress = NULL;
py_remote->transfer_progress = NULL;
py_remote->update_tips = NULL;
Remote_set_callbacks(py_remote);
}
return (PyObject *)py_remote;
}

View File

@@ -37,5 +37,6 @@ PyObject* Remote_init(Remote *self, PyObject *args, PyObject *kwds);
PyObject* Remote_fetch(Remote *self, PyObject *args);
void Remote_set_callbacks(Remote *self);
PyObject *wrap_remote(git_remote *c_remote, Repository *repo);
#endif

View File

@@ -1279,7 +1279,6 @@ PyDoc_STRVAR(Repository_create_remote__doc__,
PyObject *
Repository_create_remote(Repository *self, PyObject *args)
{
Remote *py_remote;
git_remote *remote;
char *name = NULL, *url = NULL;
int err;
@@ -1291,13 +1290,7 @@ Repository_create_remote(Repository *self, PyObject *args)
if (err < 0)
return Error_set(err);
py_remote = PyObject_New(Remote, &RemoteType);
Py_INCREF(self);
py_remote->repo = self;
py_remote->remote = remote;
Remote_set_callbacks(py_remote);
return (PyObject*) py_remote;
return (PyObject*) wrap_remote(remote, self);
}
@@ -1307,18 +1300,19 @@ PyObject *
Repository_remotes__get__(Repository *self)
{
git_strarray remotes;
git_remote *remote = NULL;
PyObject* py_list = NULL, *py_args = NULL;
Remote *py_remote;
size_t i;
int err;
git_remote_list(&remotes, self->repo);
py_list = PyList_New(remotes.count);
for (i=0; i < remotes.count; ++i) {
py_remote = PyObject_New(Remote, &RemoteType);
py_args = Py_BuildValue("Os", self, remotes.strings[i]);
Remote_init(py_remote, py_args, NULL);
PyList_SetItem(py_list, i, (PyObject*) py_remote);
err = git_remote_load(&remote, self->repo, remotes.strings[i]);
if (err < 0)
return Error_set(err);
PyList_SetItem(py_list, i, wrap_remote(remote, self));
}
git_strarray_free(&remotes);