diff --git a/pygit2.c b/pygit2.c index 00fdd02..7ca9b02 100644 --- a/pygit2.c +++ b/pygit2.c @@ -1435,6 +1435,34 @@ Index_setitem(Index *self, PyObject *key, PyObject *value) { return 0; } +static PyObject * +Index_create_tree(Index *self) { + git_oid oid; + int err; + Tree *py_tree; + git_tree *tree; + + err = git_tree_create_fromindex(&oid, self->index); + if (err < 0) { + return Error_set(err); + } + + err = git_tree_lookup(&tree, self->repo->repo, &oid); + if (err < 0) { + return Error_set(err); + } + + py_tree = PyObject_New(Tree, &TreeType); + if (!py_tree) + return NULL; + + Py_INCREF(self->repo); + py_tree->repo = self->repo; + py_tree->tree = (git_tree*)tree; + + return (PyObject*)py_tree; +} + static PyMethodDef Index_methods[] = { {"add", (PyCFunction)Index_add, METH_VARARGS, "Add or update an index entry from a file in disk."}, @@ -1449,6 +1477,8 @@ static PyMethodDef Index_methods[] = { {"write", (PyCFunction)Index_write, METH_NOARGS, "Write an existing index object from memory back to disk using an" " atomic file lock."}, + {"create_tree", (PyCFunction)Index_create_tree, METH_NOARGS, + "Create a tree from the index entries"}, {NULL} };