Add the parents attribute to commit.

Only support getting the attribute for now.
This commit is contained in:
John Szakmeister 2011-02-26 16:31:15 -05:00
parent 3b403247d1
commit 3fc9a840a1
2 changed files with 30 additions and 0 deletions

@ -644,6 +644,30 @@ Commit_set_author(Commit *commit, PyObject *value) {
return 0;
}
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 PyGetSetDef Commit_getseters[] = {
{"message_short", (getter)Commit_get_message_short, NULL, "short message",
NULL},
@ -655,6 +679,8 @@ static PyGetSetDef Commit_getseters[] = {
(setter)Commit_set_committer, "committer", NULL},
{"author", (getter)Commit_get_author,
(setter)Commit_set_author, "author", NULL},
{"parents", (getter)Commit_get_parents, NULL, "parents of this commit",
NULL},
{NULL}
};

@ -42,6 +42,10 @@ 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'),