Merge remote branch 'julien/cosmetic'
This commit is contained in:
281
pygit2.c
281
pygit2.c
@@ -42,8 +42,8 @@ typedef struct {
|
|||||||
PyObject *index; /* It will be None for a bare repository */
|
PyObject *index; /* It will be None for a bare repository */
|
||||||
} Repository;
|
} Repository;
|
||||||
|
|
||||||
/* The structs for some of the object subtypes are identical except for the
|
/* The structs for some of the object subtypes are identical except for
|
||||||
* type of their object pointers. */
|
* the type of their object pointers. */
|
||||||
#define OBJECT_STRUCT(_name, _ptr_type, _ptr_name) \
|
#define OBJECT_STRUCT(_name, _ptr_type, _ptr_name) \
|
||||||
typedef struct {\
|
typedef struct {\
|
||||||
PyObject_HEAD\
|
PyObject_HEAD\
|
||||||
@@ -138,11 +138,12 @@ Error_set(int err) {
|
|||||||
assert(err < 0);
|
assert(err < 0);
|
||||||
if (err == GIT_ENOTFOUND) {
|
if (err == GIT_ENOTFOUND) {
|
||||||
/* KeyError expects the arg to be the missing key. If the caller
|
/* KeyError expects the arg to be the missing key. If the caller
|
||||||
* called this instead of Error_set_py_obj, it means we don't know
|
* called this instead of Error_set_py_obj, it means we don't
|
||||||
* the key, but nor should we use git_lasterror. */
|
* know the key, but nor should we use git_lasterror. */
|
||||||
PyErr_SetNone(PyExc_KeyError);
|
PyErr_SetNone(PyExc_KeyError);
|
||||||
return NULL;
|
return NULL;
|
||||||
} else if (err == GIT_EOSERR) {
|
}
|
||||||
|
else if (err == GIT_EOSERR) {
|
||||||
PyErr_SetFromErrno(GitError);
|
PyErr_SetFromErrno(GitError);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -169,10 +170,12 @@ Error_set_py_obj(int err, PyObject *py_obj) {
|
|||||||
assert(err < 0);
|
assert(err < 0);
|
||||||
|
|
||||||
if (err == GIT_ENOTOID && !PyString_Check(py_obj)) {
|
if (err == GIT_ENOTOID && !PyString_Check(py_obj)) {
|
||||||
PyErr_Format(PyExc_TypeError, "Git object id must be 40 byte hexadecimal str, or 20 byte binary str: %.200s",
|
PyErr_Format(PyExc_TypeError,
|
||||||
|
"Git object id must be 40 byte hexadecimal str, or 20 byte binary str: %.200s",
|
||||||
py_obj->ob_type->tp_name);
|
py_obj->ob_type->tp_name);
|
||||||
return NULL;
|
return NULL;
|
||||||
} else if (err == GIT_ENOTFOUND) {
|
}
|
||||||
|
else if (err == GIT_ENOTFOUND) {
|
||||||
/* KeyError expects the arg to be the missing key. */
|
/* KeyError expects the arg to be the missing key. */
|
||||||
PyErr_SetObject(PyExc_KeyError, py_obj);
|
PyErr_SetObject(PyExc_KeyError, py_obj);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -261,7 +264,8 @@ py_str_to_git_oid(PyObject *py_str, git_oid *oid) {
|
|||||||
if (PyString_Size(py_str) == 20) {
|
if (PyString_Size(py_str) == 20) {
|
||||||
git_oid_fromraw(oid, (const unsigned char*)hex_or_bin);
|
git_oid_fromraw(oid, (const unsigned char*)hex_or_bin);
|
||||||
err = 0;
|
err = 0;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
err = git_oid_fromstr(oid, hex_or_bin);
|
err = git_oid_fromstr(oid, hex_or_bin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -412,10 +416,12 @@ Repository_get_index(Repository *self, void *closure) {
|
|||||||
py_index->index = index;
|
py_index->index = index;
|
||||||
py_index->own_obj = 0;
|
py_index->own_obj = 0;
|
||||||
self->index = (PyObject*)py_index;
|
self->index = (PyObject*)py_index;
|
||||||
} else if (err == GIT_EBAREINDEX) {
|
}
|
||||||
|
else if (err == GIT_EBAREINDEX) {
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
self->index = Py_None;
|
self->index = Py_None;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return Error_set(err);
|
return Error_set(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -897,26 +903,26 @@ static PyMethodDef Object_methods[] = {
|
|||||||
|
|
||||||
static PyTypeObject ObjectType = {
|
static PyTypeObject ObjectType = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
PyObject_HEAD_INIT(NULL)
|
||||||
0, /*ob_size*/
|
0, /* ob_size */
|
||||||
"pygit2.Object", /*tp_name*/
|
"pygit2.Object", /* tp_name */
|
||||||
sizeof(Object), /*tp_basicsize*/
|
sizeof(Object), /* tp_basicsize */
|
||||||
0, /*tp_itemsize*/
|
0, /* tp_itemsize */
|
||||||
(destructor)Object_dealloc, /*tp_dealloc*/
|
(destructor)Object_dealloc, /* tp_dealloc */
|
||||||
0, /*tp_print*/
|
0, /* tp_print */
|
||||||
0, /*tp_getattr*/
|
0, /* tp_getattr */
|
||||||
0, /*tp_setattr*/
|
0, /* tp_setattr */
|
||||||
0, /*tp_compare*/
|
0, /* tp_compare */
|
||||||
0, /*tp_repr*/
|
0, /* tp_repr */
|
||||||
0, /*tp_as_number*/
|
0, /* tp_as_number */
|
||||||
0, /*tp_as_sequence*/
|
0, /* tp_as_sequence */
|
||||||
0, /*tp_as_mapping*/
|
0, /* tp_as_mapping */
|
||||||
0, /*tp_hash */
|
0, /* tp_hash */
|
||||||
0, /*tp_call*/
|
0, /* tp_call */
|
||||||
0, /*tp_str*/
|
0, /* tp_str */
|
||||||
0, /*tp_getattro*/
|
0, /* tp_getattro */
|
||||||
0, /*tp_setattro*/
|
0, /* tp_setattro */
|
||||||
0, /*tp_as_buffer*/
|
0, /* tp_as_buffer */
|
||||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
|
||||||
"Object objects", /* tp_doc */
|
"Object objects", /* tp_doc */
|
||||||
0, /* tp_traverse */
|
0, /* tp_traverse */
|
||||||
0, /* tp_clear */
|
0, /* tp_clear */
|
||||||
@@ -1035,26 +1041,26 @@ static PyGetSetDef Commit_getseters[] = {
|
|||||||
|
|
||||||
static PyTypeObject CommitType = {
|
static PyTypeObject CommitType = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
PyObject_HEAD_INIT(NULL)
|
||||||
0, /*ob_size*/
|
0, /* ob_size */
|
||||||
"pygit2.Commit", /*tp_name*/
|
"pygit2.Commit", /* tp_name */
|
||||||
sizeof(Commit), /*tp_basicsize*/
|
sizeof(Commit), /* tp_basicsize */
|
||||||
0, /*tp_itemsize*/
|
0, /* tp_itemsize */
|
||||||
0, /*tp_dealloc*/
|
0, /* tp_dealloc */
|
||||||
0, /*tp_print*/
|
0, /* tp_print */
|
||||||
0, /*tp_getattr*/
|
0, /* tp_getattr */
|
||||||
0, /*tp_setattr*/
|
0, /* tp_setattr */
|
||||||
0, /*tp_compare*/
|
0, /* tp_compare */
|
||||||
0, /*tp_repr*/
|
0, /* tp_repr */
|
||||||
0, /*tp_as_number*/
|
0, /* tp_as_number */
|
||||||
0, /*tp_as_sequence*/
|
0, /* tp_as_sequence */
|
||||||
0, /*tp_as_mapping*/
|
0, /* tp_as_mapping */
|
||||||
0, /*tp_hash */
|
0, /* tp_hash */
|
||||||
0, /*tp_call*/
|
0, /* tp_call */
|
||||||
0, /*tp_str*/
|
0, /* tp_str */
|
||||||
0, /*tp_getattro*/
|
0, /* tp_getattro */
|
||||||
0, /*tp_setattro*/
|
0, /* tp_setattro */
|
||||||
0, /*tp_as_buffer*/
|
0, /* tp_as_buffer */
|
||||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
|
||||||
"Commit objects", /* tp_doc */
|
"Commit objects", /* tp_doc */
|
||||||
0, /* tp_traverse */
|
0, /* tp_traverse */
|
||||||
0, /* tp_clear */
|
0, /* tp_clear */
|
||||||
@@ -1119,26 +1125,26 @@ static PyMethodDef TreeEntry_methods[] = {
|
|||||||
|
|
||||||
static PyTypeObject TreeEntryType = {
|
static PyTypeObject TreeEntryType = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
PyObject_HEAD_INIT(NULL)
|
||||||
0, /*ob_size*/
|
0, /* ob_size */
|
||||||
"pygit2.TreeEntry", /*tp_name*/
|
"pygit2.TreeEntry", /* tp_name */
|
||||||
sizeof(TreeEntry), /*tp_basicsize*/
|
sizeof(TreeEntry), /* tp_basicsize */
|
||||||
0, /*tp_itemsize*/
|
0, /* tp_itemsize */
|
||||||
(destructor)TreeEntry_dealloc, /*tp_dealloc*/
|
(destructor)TreeEntry_dealloc, /* tp_dealloc */
|
||||||
0, /*tp_print*/
|
0, /* tp_print */
|
||||||
0, /*tp_getattr*/
|
0, /* tp_getattr */
|
||||||
0, /*tp_setattr*/
|
0, /* tp_setattr */
|
||||||
0, /*tp_compare*/
|
0, /* tp_compare */
|
||||||
0, /*tp_repr*/
|
0, /* tp_repr */
|
||||||
0, /*tp_as_number*/
|
0, /* tp_as_number */
|
||||||
0, /*tp_as_sequence*/
|
0, /* tp_as_sequence */
|
||||||
0, /*tp_as_mapping*/
|
0, /* tp_as_mapping */
|
||||||
0, /*tp_hash */
|
0, /* tp_hash */
|
||||||
0, /*tp_call*/
|
0, /* tp_call */
|
||||||
0, /*tp_str*/
|
0, /* tp_str */
|
||||||
0, /*tp_getattro*/
|
0, /* tp_getattro */
|
||||||
0, /*tp_setattro*/
|
0, /* tp_setattro */
|
||||||
0, /*tp_as_buffer*/
|
0, /* tp_as_buffer */
|
||||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
|
||||||
"TreeEntry objects", /* tp_doc */
|
"TreeEntry objects", /* tp_doc */
|
||||||
0, /* tp_traverse */
|
0, /* tp_traverse */
|
||||||
0, /* tp_clear */
|
0, /* tp_clear */
|
||||||
@@ -1218,7 +1224,8 @@ Tree_fix_index(Tree *self, PyObject *py_index) {
|
|||||||
if (index >= slen) {
|
if (index >= slen) {
|
||||||
PyErr_SetObject(PyExc_IndexError, py_index);
|
PyErr_SetObject(PyExc_IndexError, py_index);
|
||||||
return -1;
|
return -1;
|
||||||
} else if (index < -slen) {
|
}
|
||||||
|
else if (index < -slen) {
|
||||||
PyErr_SetObject(PyExc_IndexError, py_index);
|
PyErr_SetObject(PyExc_IndexError, py_index);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -1266,9 +1273,11 @@ static TreeEntry *
|
|||||||
Tree_getitem(Tree *self, PyObject *value) {
|
Tree_getitem(Tree *self, PyObject *value) {
|
||||||
if (PyString_Check(value)) {
|
if (PyString_Check(value)) {
|
||||||
return Tree_getitem_by_name(self, value);
|
return Tree_getitem_by_name(self, value);
|
||||||
} else if (PyInt_Check(value)) {
|
}
|
||||||
|
else if (PyInt_Check(value)) {
|
||||||
return Tree_getitem_by_index(self, value);
|
return Tree_getitem_by_index(self, value);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"Tree entry index must be int or str, not %.200s",
|
"Tree entry index must be int or str, not %.200s",
|
||||||
value->ob_type->tp_name);
|
value->ob_type->tp_name);
|
||||||
@@ -1295,26 +1304,26 @@ static PyMappingMethods Tree_as_mapping = {
|
|||||||
|
|
||||||
static PyTypeObject TreeType = {
|
static PyTypeObject TreeType = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
PyObject_HEAD_INIT(NULL)
|
||||||
0, /*ob_size*/
|
0, /* ob_size */
|
||||||
"pygit2.Tree", /*tp_name*/
|
"pygit2.Tree", /* tp_name */
|
||||||
sizeof(Tree), /*tp_basicsize*/
|
sizeof(Tree), /* tp_basicsize */
|
||||||
0, /*tp_itemsize*/
|
0, /* tp_itemsize */
|
||||||
0, /*tp_dealloc*/
|
0, /* tp_dealloc */
|
||||||
0, /*tp_print*/
|
0, /* tp_print */
|
||||||
0, /*tp_getattr*/
|
0, /* tp_getattr */
|
||||||
0, /*tp_setattr*/
|
0, /* tp_setattr */
|
||||||
0, /*tp_compare*/
|
0, /* tp_compare */
|
||||||
0, /*tp_repr*/
|
0, /* tp_repr */
|
||||||
0, /*tp_as_number*/
|
0, /* tp_as_number */
|
||||||
&Tree_as_sequence, /*tp_as_sequence*/
|
&Tree_as_sequence, /* tp_as_sequence */
|
||||||
&Tree_as_mapping, /*tp_as_mapping*/
|
&Tree_as_mapping, /* tp_as_mapping */
|
||||||
0, /*tp_hash */
|
0, /* tp_hash */
|
||||||
0, /*tp_call*/
|
0, /* tp_call */
|
||||||
0, /*tp_str*/
|
0, /* tp_str */
|
||||||
0, /*tp_getattro*/
|
0, /* tp_getattro */
|
||||||
0, /*tp_setattro*/
|
0, /* tp_setattro */
|
||||||
0, /*tp_as_buffer*/
|
0, /* tp_as_buffer */
|
||||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
|
||||||
"Tree objects", /* tp_doc */
|
"Tree objects", /* tp_doc */
|
||||||
0, /* tp_traverse */
|
0, /* tp_traverse */
|
||||||
0, /* tp_clear */
|
0, /* tp_clear */
|
||||||
@@ -1391,26 +1400,26 @@ static PyGetSetDef Blob_getseters[] = {
|
|||||||
|
|
||||||
static PyTypeObject BlobType = {
|
static PyTypeObject BlobType = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
PyObject_HEAD_INIT(NULL)
|
||||||
0, /*ob_size*/
|
0, /* ob_size */
|
||||||
"pygit2.Blob", /*tp_name*/
|
"pygit2.Blob", /* tp_name */
|
||||||
sizeof(Blob), /*tp_basicsize*/
|
sizeof(Blob), /* tp_basicsize */
|
||||||
0, /*tp_itemsize*/
|
0, /* tp_itemsize */
|
||||||
0, /*tp_dealloc*/
|
0, /* tp_dealloc */
|
||||||
0, /*tp_print*/
|
0, /* tp_print */
|
||||||
0, /*tp_getattr*/
|
0, /* tp_getattr */
|
||||||
0, /*tp_setattr*/
|
0, /* tp_setattr */
|
||||||
0, /*tp_compare*/
|
0, /* tp_compare */
|
||||||
0, /*tp_repr*/
|
0, /* tp_repr */
|
||||||
0, /*tp_as_number*/
|
0, /* tp_as_number */
|
||||||
0, /*tp_as_sequence*/
|
0, /* tp_as_sequence */
|
||||||
0, /*tp_as_mapping*/
|
0, /* tp_as_mapping */
|
||||||
0, /*tp_hash */
|
0, /* tp_hash */
|
||||||
0, /*tp_call*/
|
0, /* tp_call */
|
||||||
0, /*tp_str*/
|
0, /* tp_str */
|
||||||
0, /*tp_getattro*/
|
0, /* tp_getattro */
|
||||||
0, /*tp_setattro*/
|
0, /* tp_setattro */
|
||||||
0, /*tp_as_buffer*/
|
0, /* tp_as_buffer */
|
||||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
|
||||||
"Blob objects", /* tp_doc */
|
"Blob objects", /* tp_doc */
|
||||||
0, /* tp_traverse */
|
0, /* tp_traverse */
|
||||||
0, /* tp_clear */
|
0, /* tp_clear */
|
||||||
@@ -1491,26 +1500,26 @@ static PyGetSetDef Tag_getseters[] = {
|
|||||||
|
|
||||||
static PyTypeObject TagType = {
|
static PyTypeObject TagType = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
PyObject_HEAD_INIT(NULL)
|
||||||
0, /*ob_size*/
|
0, /* ob_size */
|
||||||
"pygit2.Tag", /*tp_name*/
|
"pygit2.Tag", /* tp_name */
|
||||||
sizeof(Tag), /*tp_basicsize*/
|
sizeof(Tag), /* tp_basicsize */
|
||||||
0, /*tp_itemsize*/
|
0, /* tp_itemsize */
|
||||||
(destructor)Tag_dealloc, /*tp_dealloc*/
|
(destructor)Tag_dealloc, /* tp_dealloc */
|
||||||
0, /*tp_print*/
|
0, /* tp_print */
|
||||||
0, /*tp_getattr*/
|
0, /* tp_getattr */
|
||||||
0, /*tp_setattr*/
|
0, /* tp_setattr */
|
||||||
0, /*tp_compare*/
|
0, /* tp_compare */
|
||||||
0, /*tp_repr*/
|
0, /* tp_repr */
|
||||||
0, /*tp_as_number*/
|
0, /* tp_as_number */
|
||||||
0, /*tp_as_sequence*/
|
0, /* tp_as_sequence */
|
||||||
0, /*tp_as_mapping*/
|
0, /* tp_as_mapping */
|
||||||
0, /*tp_hash */
|
0, /* tp_hash */
|
||||||
0, /*tp_call*/
|
0, /* tp_call */
|
||||||
0, /*tp_str*/
|
0, /* tp_str */
|
||||||
0, /*tp_getattro*/
|
0, /* tp_getattro */
|
||||||
0, /*tp_setattro*/
|
0, /* tp_setattro */
|
||||||
0, /*tp_as_buffer*/
|
0, /* tp_as_buffer */
|
||||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
|
||||||
"Tag objects", /* tp_doc */
|
"Tag objects", /* tp_doc */
|
||||||
0, /* tp_traverse */
|
0, /* tp_traverse */
|
||||||
0, /* tp_clear */
|
0, /* tp_clear */
|
||||||
@@ -1639,7 +1648,8 @@ Index_get_position(Index *self, PyObject *value) {
|
|||||||
Error_set_str(idx, path);
|
Error_set_str(idx, path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else if (PyInt_Check(value)) {
|
}
|
||||||
|
else if (PyInt_Check(value)) {
|
||||||
idx = (int)PyInt_AsLong(value);
|
idx = (int)PyInt_AsLong(value);
|
||||||
if (idx == -1 && PyErr_Occurred())
|
if (idx == -1 && PyErr_Occurred())
|
||||||
return -1;
|
return -1;
|
||||||
@@ -1647,7 +1657,8 @@ Index_get_position(Index *self, PyObject *value) {
|
|||||||
PyErr_SetObject(PyExc_ValueError, value);
|
PyErr_SetObject(PyExc_ValueError, value);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"Index entry key must be int or str, not %.200s",
|
"Index entry key must be int or str, not %.200s",
|
||||||
value->ob_type->tp_name);
|
value->ob_type->tp_name);
|
||||||
|
Reference in New Issue
Block a user