Implement Commit.tree getter

We need this to be able to make an equivalent to "git log -- path"
This commit is contained in:
J. David Ibáñez 2011-02-23 16:02:15 +01:00
parent 0032573ca8
commit 7e8d2bb19d
2 changed files with 25 additions and 2 deletions

@ -737,6 +737,24 @@ Commit_set_author(Commit *commit, PyObject *value) {
return 0;
}
static PyObject *
Commit_get_tree(Commit *commit) {
const git_tree *tree;
Tree *py_tree;
tree = git_commit_tree(commit->commit);
if (tree == NULL)
Py_RETURN_NONE;
py_tree = PyObject_New(Tree, &TreeType);
Py_INCREF(commit->repo);
py_tree->repo = commit->repo;
py_tree->own_obj = 0;
py_tree->tree = (git_tree*)tree;
return (PyObject*)py_tree;
}
static PyGetSetDef Commit_getseters[] = {
{"message_short", (getter)Commit_get_message_short, NULL, "short message",
NULL},
@ -748,6 +766,7 @@ static PyGetSetDef Commit_getseters[] = {
(setter)Commit_set_committer, "committer", NULL},
{"author", (getter)Commit_get_author,
(setter)Commit_set_author, "author", NULL},
{"tree", (getter)Commit_get_tree, NULL, "tree object"},
{NULL}
};

@ -47,10 +47,13 @@ class CommitTest(utils.BareRepoTestCase):
commit.message)
commit_time = 1288481576
self.assertEqual(commit_time, commit.commit_time)
self.assertEqual(('Dave Borowitz', 'dborowitz@google.com', commit_time),
commit.committer)
self.assertEqual(
('Dave Borowitz', 'dborowitz@google.com', commit_time),
commit.committer)
self.assertEqual(('Dave Borowitz', 'dborowitz@google.com', 1288477363),
commit.author)
self.assertEqual(
'967fce8df97cc71722d3c2a5930ef3e6f1d27b12', commit.tree.sha)
def test_new_commit(self):
message = 'New commit.\n\nMessage.\n'
@ -71,6 +74,7 @@ class CommitTest(utils.BareRepoTestCase):
#self.assertEqual(12346, commit.commit_time)
self.assertEqual(committer, commit.committer)
self.assertEqual(author, commit.author)
self.assertEqual(None, commit.tree)
def test_modify_commit(self):
message = 'New commit.\n\nMessage.\n'