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:
Carlos Martín Nieto 2014-01-21 03:38:22 +01:00
parent 9c95cb0560
commit d98a701477
2 changed files with 28 additions and 2 deletions

View File

@ -39,6 +39,7 @@ extern PyTypeObject TreeType;
extern PyTypeObject DiffType;
extern PyTypeObject IndexIterType;
extern PyTypeObject IndexEntryType;
extern PyTypeObject OidType;
int
Index_init(Index *self, PyObject *args, PyObject *kwds)
@ -564,6 +565,31 @@ PyTypeObject IndexIterType = {
(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
IndexEntry_dealloc(IndexEntry *self)
{
@ -652,7 +678,7 @@ PyTypeObject IndexEntryType = {
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
(initproc)IndexEntry_init, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};

View File

@ -343,7 +343,7 @@ moduleinit(PyObject* m)
* Index & Working copy
*/
INIT_TYPE(IndexType, NULL, PyType_GenericNew)
INIT_TYPE(IndexEntryType, NULL, NULL)
INIT_TYPE(IndexEntryType, NULL, PyType_GenericNew)
INIT_TYPE(IndexIterType, NULL, NULL)
ADD_TYPE(m, Index)
ADD_TYPE(m, IndexEntry)