Merge remote branch 'john/add-commit-attributes' into revwalk
Conflicts: pygit2.c test/test_commit.py
This commit is contained in:
commit
8da3f16da7
66
pygit2.c
66
pygit2.c
@ -755,6 +755,62 @@ Commit_get_tree(Commit *commit) {
|
||||
return (PyObject*)py_tree;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
Commit_get_parents(Commit *commit)
|
||||
{
|
||||
unsigned int parent_count = git_commit_parentcount(commit->commit);
|
||||
unsigned int i;
|
||||
git_commit *parent;
|
||||
Object *obj;
|
||||
|
||||
PyObject *list = PyList_New(parent_count);
|
||||
if (!list)
|
||||
return NULL;
|
||||
|
||||
for (i=0; i < parent_count; i++) {
|
||||
parent = git_commit_parent(commit->commit, i);
|
||||
obj = wrap_object((git_object *)parent, commit->repo);
|
||||
obj->own_obj = 0;
|
||||
|
||||
PyList_SET_ITEM(list, i, (PyObject *)obj);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
Commit_add_parent(Commit *self, PyObject *parent)
|
||||
{
|
||||
int err;
|
||||
git_commit *parent_commit;
|
||||
|
||||
if (PyString_Check(parent)) {
|
||||
git_oid oid;
|
||||
|
||||
err = py_str_to_git_oid(parent, &oid);
|
||||
if (err < 0)
|
||||
return Error_set_py_obj(err, parent);
|
||||
|
||||
err = git_commit_lookup(&parent_commit, self->repo->repo, &oid);
|
||||
if (err < 0)
|
||||
return Error_set_py_obj(err, parent);
|
||||
} else {
|
||||
if (!PyObject_TypeCheck(parent, &CommitType)) {
|
||||
PyErr_Format(PyExc_TypeError, "target must be %.200s, not %.200s",
|
||||
CommitType.tp_name, parent->ob_type->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
parent_commit = ((Commit *) parent)->commit;
|
||||
}
|
||||
|
||||
err = git_commit_add_parent(self->commit, parent_commit);
|
||||
if (err < 0)
|
||||
return Error_set(err);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyGetSetDef Commit_getseters[] = {
|
||||
{"message_short", (getter)Commit_get_message_short, NULL, "short message",
|
||||
NULL},
|
||||
@ -767,6 +823,14 @@ static PyGetSetDef Commit_getseters[] = {
|
||||
{"author", (getter)Commit_get_author,
|
||||
(setter)Commit_set_author, "author", NULL},
|
||||
{"tree", (getter)Commit_get_tree, NULL, "tree object", NULL},
|
||||
{"parents", (getter)Commit_get_parents, NULL, "parents of this commit",
|
||||
NULL},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
static PyMethodDef Commit_methods[] = {
|
||||
{"add_parent", (PyCFunction)Commit_add_parent, METH_O,
|
||||
"Add a new parent commit to an existing commit."},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
@ -799,7 +863,7 @@ static PyTypeObject CommitType = {
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
Commit_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
Commit_getseters, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
|
@ -41,6 +41,11 @@ class CommitTest(utils.BareRepoTestCase):
|
||||
|
||||
def test_read_commit(self):
|
||||
commit = self.repo[COMMIT_SHA]
|
||||
self.assertEqual(COMMIT_SHA, commit.sha)
|
||||
parents = commit.parents
|
||||
self.assertEqual(1, len(parents))
|
||||
self.assertEqual('c2792cfa289ae6321ecf2cd5806c2194b0fd070c',
|
||||
parents[0].sha)
|
||||
self.assertEqual('Second test data commit.', commit.message_short)
|
||||
self.assertEqual(('Second test data commit.\n\n'
|
||||
'This commit has some additional text.\n'),
|
||||
@ -65,16 +70,20 @@ class CommitTest(utils.BareRepoTestCase):
|
||||
commit.committer = committer
|
||||
commit.author = author
|
||||
|
||||
self.assertEqual(0, len(commit.parents))
|
||||
|
||||
commit.add_parent(COMMIT_SHA)
|
||||
|
||||
self.assertEqual(None, commit.sha)
|
||||
self.assertEqual(pygit2.GIT_OBJ_COMMIT, commit.type)
|
||||
self.assertEqual(message, commit.message)
|
||||
# TODO: Uncomment when git_commit_set_message updates message_short.
|
||||
#self.assertEqual('New commit.', commit.message_short)
|
||||
# TODO: Uncomment when git_commit_set_committer updates commit_time.
|
||||
#self.assertEqual(12346, commit.commit_time)
|
||||
self.assertEqual('New commit.', commit.message_short)
|
||||
self.assertEqual(12346, commit.commit_time)
|
||||
self.assertEqual(committer, commit.committer)
|
||||
self.assertEqual(author, commit.author)
|
||||
self.assertEqual(None, commit.tree)
|
||||
self.assertEqual(1, len(commit.parents))
|
||||
self.assertEqual(COMMIT_SHA, commit.parents[0].sha)
|
||||
|
||||
def test_modify_commit(self):
|
||||
message = 'New commit.\n\nMessage.\n'
|
||||
@ -87,10 +96,8 @@ class CommitTest(utils.BareRepoTestCase):
|
||||
commit.author = author
|
||||
|
||||
self.assertEqual(message, commit.message)
|
||||
# TODO: Uncomment when libgit2 supports changing message_short.
|
||||
#self.assertEqual('New commit.', commit.message_short)
|
||||
# TODO: Uncomment when libgit2 supports changing commit_time.
|
||||
#self.assertEqual(12346, commit.commit_time)
|
||||
self.assertEqual('New commit.', commit.message_short)
|
||||
self.assertEqual(12346, commit.commit_time)
|
||||
self.assertEqual(committer, commit.committer)
|
||||
self.assertEqual(author, commit.author)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user