Factor out a helper function for initializing Objects.
Change-Id: Ibf1585bbd4fd5adfb835e34d02fc6186a97d1cd9
This commit is contained in:
parent
3fa91b901d
commit
fe39b53757
33
pygit2.c
33
pygit2.c
@ -376,22 +376,31 @@ static PyTypeObject ObjectType = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
Commit_init(Commit *py_commit, PyObject *args, PyObject **kwds) {
|
object_init_check(const char *type_name, PyObject *args, PyObject *kwds,
|
||||||
|
Repository **repo) {
|
||||||
|
if (kwds) {
|
||||||
|
PyErr_Format(PyExc_TypeError, "%s takes no keyword arugments",
|
||||||
|
type_name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!PyArg_ParseTuple(args, "O", repo))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!PyObject_TypeCheck(*repo, &RepositoryType)) {
|
||||||
|
PyErr_SetString(PyExc_TypeError, "Expected Repository for repo");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
Commit_init(Commit *py_commit, PyObject *args, PyObject *kwds) {
|
||||||
Repository *repo = NULL;
|
Repository *repo = NULL;
|
||||||
git_commit *commit;
|
git_commit *commit;
|
||||||
|
|
||||||
if (kwds) {
|
if (!object_init_check("Commit", args, kwds, &repo))
|
||||||
PyErr_SetString(PyExc_TypeError, "Commit takes no keyword arugments");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "O", &repo))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (!PyObject_TypeCheck(repo, &RepositoryType)) {
|
|
||||||
PyErr_SetString(PyExc_TypeError, "Expected Repository for repo");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
commit = git_commit_new(repo->repo);
|
commit = git_commit_new(repo->repo);
|
||||||
if (!commit) {
|
if (!commit) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user