Skip to content

Commit

Permalink
Add wrap remote.
Browse files Browse the repository at this point in the history
  • Loading branch information
xtao committed Jan 29, 2014
1 parent 94e841b commit 5b4b7f3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
20 changes: 19 additions & 1 deletion src/remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions src/remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 7 additions & 13 deletions src/repository.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}


Expand All @@ -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);
Expand Down

0 comments on commit 5b4b7f3

Please sign in to comment.