Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wrap_remote. #332

Merged
merged 2 commits into from
Jan 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 27 additions & 41 deletions src/remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,45 +461,6 @@ update_tips_cb(const char *refname, const git_oid *a, const git_oid *b, void *da
return 0;
}

PyObject *
Remote_init(Remote *self, PyObject *args, PyObject *kwds)
{
Repository* py_repo = NULL;
char *name = NULL;
int err;

if (!PyArg_ParseTuple(args, "O!s", &RepositoryType, &py_repo, &name))
return NULL;

self->repo = py_repo;
Py_INCREF(self->repo);
err = git_remote_load(&self->remote, py_repo->repo, name);

if (err < 0)
return Error_set(err);

self->progress = NULL;
self->transfer_progress = NULL;
self->update_tips = NULL;

Remote_set_callbacks(self);
return (PyObject*) self;
}

void
Remote_set_callbacks(Remote *self)
{
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;

self->progress = NULL;

callbacks.progress = progress_cb;
callbacks.transfer_progress = transfer_progress_cb;
callbacks.update_tips = update_tips_cb;
callbacks.payload = self;
git_remote_set_callbacks(self->remote, &callbacks);
}

static void
Remote_dealloc(Remote *self)
{
Expand Down Expand Up @@ -1036,7 +997,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 @@ -1077,7 +1038,32 @@ PyTypeObject RemoteType = {
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
(initproc)Remote_init, /* tp_init */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};

PyObject *
wrap_remote(git_remote *c_remote, Repository *repo)
{
Remote *py_remote = NULL;
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;

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;

callbacks.progress = progress_cb;
callbacks.transfer_progress = transfer_progress_cb;
callbacks.update_tips = update_tips_cb;
callbacks.payload = py_remote;
git_remote_set_callbacks(c_remote, &callbacks);
}

return (PyObject *)py_remote;
}
2 changes: 1 addition & 1 deletion src/remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
#include <git2.h>
#include <git2/remote.h>

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
35 changes: 20 additions & 15 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,23 +1300,35 @@ PyObject *
Repository_remotes__get__(Repository *self)
{
git_strarray remotes;
PyObject* py_list = NULL, *py_args = NULL;
Remote *py_remote;
git_remote *remote = NULL;
PyObject *py_list = NULL;
PyObject *py_remote = NULL;
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)
goto cleanup;
py_remote = wrap_remote(remote, self);
if (py_remote == NULL)
goto cleanup;
PyList_SetItem(py_list, i, py_remote);
}

git_strarray_free(&remotes);

return (PyObject*) py_list;

cleanup:
git_strarray_free(&remotes);
if (py_list)
Py_DECREF(py_list);
if (err < 0)
return Error_set(err);
return NULL;
}

PyDoc_STRVAR(Repository_default_signature__doc__, "Return the signature according to the repository's configuration");
Expand Down