Add create_tree method for Index class

Invoke tree = index.create_tree() to create a tree from index file and return Tree object.
This commit is contained in:
Sarath Lakshman
2011-04-07 14:02:57 +05:30
parent fca3a4753b
commit e7fe537626

View File

@@ -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}
};