diff --git a/src/remote.c b/src/remote.c index 8201a9035..3f2388cb4 100644 --- a/src/remote.c +++ b/src/remote.c @@ -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) { @@ -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 */ }; @@ -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); @@ -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; diff --git a/src/remote.h b/src/remote.h index 1deedcd50..426314038 100644 --- a/src/remote.h +++ b/src/remote.h @@ -33,7 +33,6 @@ #include #include -PyObject* Remote_init(Remote *self, PyObject *args, PyObject *kwds); PyObject* Remote_fetch(Remote *self, PyObject *args); void Remote_set_callbacks(Remote *self); diff --git a/src/repository.c b/src/repository.c index c1fa44ccd..00d9cc55e 100644 --- a/src/repository.c +++ b/src/repository.c @@ -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; @@ -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");