Update various calls to new error-code-returning interface.
Change-Id: I56d60a99e5eb251825b1225b06dadb7848d5b2dd
This commit is contained in:
37
pygit2.c
37
pygit2.c
@@ -157,6 +157,7 @@ py_str_to_git_oid(PyObject *py_str, git_oid *oid) {
|
|||||||
static int
|
static int
|
||||||
Repository_init(Repository *self, PyObject *args, PyObject *kwds) {
|
Repository_init(Repository *self, PyObject *args, PyObject *kwds) {
|
||||||
char *path;
|
char *path;
|
||||||
|
int err;
|
||||||
|
|
||||||
if (kwds) {
|
if (kwds) {
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
@@ -167,10 +168,9 @@ Repository_init(Repository *self, PyObject *args, PyObject *kwds) {
|
|||||||
if (!PyArg_ParseTuple(args, "s", &path))
|
if (!PyArg_ParseTuple(args, "s", &path))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
self->repo = git_repository_open(path);
|
err = git_repository_open(&self->repo, path);
|
||||||
if (!self->repo) {
|
if (err < 0) {
|
||||||
PyErr_Format(PyExc_RuntimeError, "Failed to open repo directory at %s",
|
Error_set_str(err, path);
|
||||||
path);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,12 +256,9 @@ Repository_getitem(Repository *self, PyObject *value) {
|
|||||||
if (err < 0)
|
if (err < 0)
|
||||||
return Error_set_py_obj(err, value);
|
return Error_set_py_obj(err, value);
|
||||||
|
|
||||||
obj = git_repository_lookup(self->repo, &oid, GIT_OBJ_ANY);
|
err = git_repository_lookup(&obj, self->repo, &oid, GIT_OBJ_ANY);
|
||||||
/* Grr, libgit2 currently doesn't give us any info on this error, so we
|
if (err < 0)
|
||||||
* can't even tell the difference between a missing object and, say, an I/O
|
return Error_set_py_obj(err, value);
|
||||||
* error. */
|
|
||||||
if (!obj)
|
|
||||||
return Error_set_py_obj(GIT_ENOTFOUND, value);
|
|
||||||
|
|
||||||
py_obj = wrap_object(obj, self);
|
py_obj = wrap_object(obj, self);
|
||||||
if (!py_obj)
|
if (!py_obj)
|
||||||
@@ -488,6 +485,7 @@ Object_init_with_type(Object *py_obj, const git_otype type, PyObject *args,
|
|||||||
PyObject *kwds) {
|
PyObject *kwds) {
|
||||||
Repository *repo = NULL;
|
Repository *repo = NULL;
|
||||||
git_object *obj;
|
git_object *obj;
|
||||||
|
int err;
|
||||||
|
|
||||||
if (kwds) {
|
if (kwds) {
|
||||||
PyErr_Format(PyExc_TypeError, "%s takes no keyword arugments",
|
PyErr_Format(PyExc_TypeError, "%s takes no keyword arugments",
|
||||||
@@ -505,9 +503,9 @@ Object_init_with_type(Object *py_obj, const git_otype type, PyObject *args,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
obj = git_object_new(repo->repo, type);
|
err = git_repository_newobject(&obj, repo->repo, type);
|
||||||
if (!obj) {
|
if (err < 0) {
|
||||||
PyErr_SetNone(PyExc_MemoryError);
|
Error_set(err);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
Py_INCREF(repo);
|
Py_INCREF(repo);
|
||||||
@@ -713,15 +711,14 @@ TreeEntry_set_sha(TreeEntry *self, PyObject *value) {
|
|||||||
static PyObject *
|
static PyObject *
|
||||||
TreeEntry_to_object(TreeEntry *self) {
|
TreeEntry_to_object(TreeEntry *self) {
|
||||||
git_object *obj;
|
git_object *obj;
|
||||||
char hex[GIT_OID_HEXSZ];
|
int err;
|
||||||
PyObject *py_hex;
|
char hex[GIT_OID_HEXSZ + 1];
|
||||||
|
|
||||||
obj = git_tree_entry_2object(self->entry);
|
err = git_tree_entry_2object(&obj, self->entry);
|
||||||
if (!obj) {
|
if (err < 0) {
|
||||||
git_oid_fmt(hex, git_tree_entry_id(self->entry));
|
git_oid_fmt(hex, git_tree_entry_id(self->entry));
|
||||||
py_hex = PyString_FromStringAndSize(hex, GIT_OID_HEXSZ);
|
hex[GIT_OID_HEXSZ] = '\0';
|
||||||
PyErr_SetObject(PyExc_KeyError, py_hex);
|
return Error_set_str(err, hex);
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
return (PyObject*)wrap_object(obj, self->tree->repo);
|
return (PyObject*)wrap_object(obj, self->tree->repo);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user