Merge remote branch 't3/master' into development
This commit is contained in:
30
pygit2.c
30
pygit2.c
@@ -1436,6 +1436,34 @@ Index_setitem(Index *self, PyObject *key, PyObject *value) {
|
|||||||
return 0;
|
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[] = {
|
static PyMethodDef Index_methods[] = {
|
||||||
{"add", (PyCFunction)Index_add, METH_VARARGS,
|
{"add", (PyCFunction)Index_add, METH_VARARGS,
|
||||||
"Add or update an index entry from a file in disk."},
|
"Add or update an index entry from a file in disk."},
|
||||||
@@ -1450,6 +1478,8 @@ static PyMethodDef Index_methods[] = {
|
|||||||
{"write", (PyCFunction)Index_write, METH_NOARGS,
|
{"write", (PyCFunction)Index_write, METH_NOARGS,
|
||||||
"Write an existing index object from memory back to disk using an"
|
"Write an existing index object from memory back to disk using an"
|
||||||
" atomic file lock."},
|
" atomic file lock."},
|
||||||
|
{"create_tree", (PyCFunction)Index_create_tree, METH_NOARGS,
|
||||||
|
"Create a tree from the index entries"},
|
||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -88,6 +88,13 @@ class IndexTest(utils.RepoTestCase):
|
|||||||
index.read()
|
index.read()
|
||||||
self.assertTrue('bye.txt' in index)
|
self.assertTrue('bye.txt' in index)
|
||||||
|
|
||||||
|
def test_create_tree(self):
|
||||||
|
sha = 'fd937514cb799514d4b81bb24c5fcfeb6472b245'
|
||||||
|
index = self.repo.index
|
||||||
|
index.read()
|
||||||
|
tree = index.create_tree()
|
||||||
|
self.assertEqual(sha, tree.sha)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Reference in New Issue
Block a user