Skip to content

Commit

Permalink
Drop Remote_init.
Browse files Browse the repository at this point in the history
  • Loading branch information
xtao committed Jan 29, 2014
1 parent 5b4b7f3 commit f79ae6b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 46 deletions.
50 changes: 9 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 @@ -1077,7 +1038,7 @@ 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 */
};
Expand All @@ -1086,6 +1047,8 @@ 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);
Expand All @@ -1094,7 +1057,12 @@ wrap_remote(git_remote *c_remote, Repository *repo)
py_remote->progress = NULL;
py_remote->transfer_progress = NULL;
py_remote->update_tips = NULL;
Remote_set_callbacks(py_remote);

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;
Expand Down
1 change: 0 additions & 1 deletion src/remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#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);
Expand Down
19 changes: 15 additions & 4 deletions src/repository.c
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,8 @@ Repository_remotes__get__(Repository *self)
{
git_strarray remotes;
git_remote *remote = NULL;
PyObject* py_list = NULL, *py_args = NULL;
PyObject *py_list = NULL;
PyObject *py_remote = NULL;
size_t i;
int err;

Expand All @@ -1311,13 +1312,23 @@ Repository_remotes__get__(Repository *self)
for (i=0; i < remotes.count; ++i) {
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));
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

0 comments on commit f79ae6b

Please sign in to comment.