git_object_id cannot return NULL
This commit is contained in:
31
pygit2.c
31
pygit2.c
@@ -964,8 +964,7 @@ Object_get_oid(Object *self)
|
|||||||
const git_oid *oid;
|
const git_oid *oid;
|
||||||
|
|
||||||
oid = git_object_id(self->obj);
|
oid = git_object_id(self->obj);
|
||||||
if (!oid)
|
assert(oid);
|
||||||
Py_RETURN_NONE;
|
|
||||||
|
|
||||||
return PyString_FromStringAndSize(oid->id, GIT_OID_RAWSZ);
|
return PyString_FromStringAndSize(oid->id, GIT_OID_RAWSZ);
|
||||||
}
|
}
|
||||||
@@ -976,8 +975,7 @@ Object_get_hex(Object *self)
|
|||||||
const git_oid *oid;
|
const git_oid *oid;
|
||||||
|
|
||||||
oid = git_object_id(self->obj);
|
oid = git_object_id(self->obj);
|
||||||
if (!oid)
|
assert(oid);
|
||||||
Py_RETURN_NONE;
|
|
||||||
|
|
||||||
return git_oid_to_py_str(oid);
|
return git_oid_to_py_str(oid);
|
||||||
}
|
}
|
||||||
@@ -991,31 +989,28 @@ Object_get_type(Object *self)
|
|||||||
static PyObject *
|
static PyObject *
|
||||||
Object_read_raw(Object *self)
|
Object_read_raw(Object *self)
|
||||||
{
|
{
|
||||||
const git_oid *id;
|
const git_oid *oid;
|
||||||
git_odb_object *obj;
|
git_odb_object *obj;
|
||||||
int err;
|
int err;
|
||||||
PyObject *result = NULL, *py_hex = NULL;
|
PyObject *aux = NULL;
|
||||||
|
|
||||||
id = git_object_id(self->obj);
|
oid = git_object_id(self->obj);
|
||||||
if (!id)
|
assert(oid);
|
||||||
Py_RETURN_NONE; /* in-memory object */
|
|
||||||
|
|
||||||
err = Repository_read_raw(&obj, self->repo->repo, id);
|
err = Repository_read_raw(&obj, self->repo->repo, oid);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
py_hex = Object_get_hex(self);
|
aux = git_oid_to_py_str(oid);
|
||||||
Error_set_py_obj(err, py_hex);
|
Error_set_py_obj(err, aux);
|
||||||
goto cleanup;
|
Py_XDECREF(aux);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = PyString_FromStringAndSize(
|
aux = PyString_FromStringAndSize(
|
||||||
git_odb_object_data(obj),
|
git_odb_object_data(obj),
|
||||||
git_odb_object_size(obj));
|
git_odb_object_size(obj));
|
||||||
|
|
||||||
git_odb_object_close(obj);
|
git_odb_object_close(obj);
|
||||||
|
return aux;
|
||||||
cleanup:
|
|
||||||
Py_XDECREF(py_hex);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyGetSetDef Object_getseters[] = {
|
static PyGetSetDef Object_getseters[] = {
|
||||||
|
Reference in New Issue
Block a user