IndexEntry: allow creation of this object
They are not required to belong to a particular index, so it should be possible to create them at runtime in order to insert them.
This commit is contained in:
28
src/index.c
28
src/index.c
@@ -39,6 +39,7 @@ extern PyTypeObject TreeType;
|
|||||||
extern PyTypeObject DiffType;
|
extern PyTypeObject DiffType;
|
||||||
extern PyTypeObject IndexIterType;
|
extern PyTypeObject IndexIterType;
|
||||||
extern PyTypeObject IndexEntryType;
|
extern PyTypeObject IndexEntryType;
|
||||||
|
extern PyTypeObject OidType;
|
||||||
|
|
||||||
int
|
int
|
||||||
Index_init(Index *self, PyObject *args, PyObject *kwds)
|
Index_init(Index *self, PyObject *args, PyObject *kwds)
|
||||||
@@ -564,6 +565,31 @@ PyTypeObject IndexIterType = {
|
|||||||
(iternextfunc)IndexIter_iternext, /* tp_iternext */
|
(iternextfunc)IndexIter_iternext, /* tp_iternext */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
IndexEntry_init(IndexEntry *self, PyObject *args, PyObject *kwds)
|
||||||
|
{
|
||||||
|
char *c_path = NULL;
|
||||||
|
Oid *id = NULL;
|
||||||
|
unsigned int mode;
|
||||||
|
char *keywords[] = {"path", "oid", "mode", NULL};
|
||||||
|
|
||||||
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "sO!I", keywords,
|
||||||
|
&c_path, &OidType, &id, &mode))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
memset(&self->entry, 0, sizeof(struct git_index_entry));
|
||||||
|
if (c_path)
|
||||||
|
self->entry.path = c_path;
|
||||||
|
|
||||||
|
if (id)
|
||||||
|
git_oid_cpy(&self->entry.oid, &id->oid);
|
||||||
|
|
||||||
|
if (mode)
|
||||||
|
self->entry.mode = mode;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
IndexEntry_dealloc(IndexEntry *self)
|
IndexEntry_dealloc(IndexEntry *self)
|
||||||
{
|
{
|
||||||
@@ -652,7 +678,7 @@ PyTypeObject IndexEntryType = {
|
|||||||
0, /* tp_descr_get */
|
0, /* tp_descr_get */
|
||||||
0, /* tp_descr_set */
|
0, /* tp_descr_set */
|
||||||
0, /* tp_dictoffset */
|
0, /* tp_dictoffset */
|
||||||
0, /* tp_init */
|
(initproc)IndexEntry_init, /* tp_init */
|
||||||
0, /* tp_alloc */
|
0, /* tp_alloc */
|
||||||
0, /* tp_new */
|
0, /* tp_new */
|
||||||
};
|
};
|
||||||
|
@@ -343,7 +343,7 @@ moduleinit(PyObject* m)
|
|||||||
* Index & Working copy
|
* Index & Working copy
|
||||||
*/
|
*/
|
||||||
INIT_TYPE(IndexType, NULL, PyType_GenericNew)
|
INIT_TYPE(IndexType, NULL, PyType_GenericNew)
|
||||||
INIT_TYPE(IndexEntryType, NULL, NULL)
|
INIT_TYPE(IndexEntryType, NULL, PyType_GenericNew)
|
||||||
INIT_TYPE(IndexIterType, NULL, NULL)
|
INIT_TYPE(IndexIterType, NULL, NULL)
|
||||||
ADD_TYPE(m, Index)
|
ADD_TYPE(m, Index)
|
||||||
ADD_TYPE(m, IndexEntry)
|
ADD_TYPE(m, IndexEntry)
|
||||||
|
Reference in New Issue
Block a user