8000 Commit: retrieve tree and parents' ids directly by carlosmn · Pull Request #311 · libgit2/pygit2 · GitHub
[go: up one dir, main page]

Skip to content

Commit: retrieve tree and parents' ids directly #311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 19, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Commit: allow retrieval of the tree's ID
Let the user retrieve the ID of the commit's tree instead of having to
load the tree just to retrieve this information.
  • Loading branch information
carlosmn committed Jan 19, 2014
commit 5a80091c2d42f2c5598d8e699ce3d1bb9669afcc
10 changes: 9 additions & 1 deletion src/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "signature.h"
#include "commit.h"
#include "object.h"
#include "oid.h"

extern PyTypeObject TreeType;

Expand Down Expand Up @@ -120,7 +121,6 @@ Commit_author__get__(Commit *self)
return build_signature((Object*)self, signature, encoding);
}


PyDoc_STRVAR(Commit_tree__doc__, "The tree object attached to the commit.");

PyObject *
Expand All @@ -146,6 +146,13 @@ Commit_tree__get__(Commit *commit)
return (PyObject*)py_tree;
}

PyDoc_STRVAR(Commit_tree_id__doc__, "The id of the tree attached to the commit.");

PyObject *
Commit_tree_id__get__(Commit *commit)
{
return git_oid_to_python(git_commit_tree_id(commit->commit));
}

PyDoc_STRVAR(Commit_parents__doc__, "The list of parent commits.");

Expand Down Expand Up @@ -201,6 +208,7 @@ PyGetSetDef Commit_getseters[] = {
GETTER(Commit, committer),
GETTER(Commit, author),
GETTER(Commit, tree),
GETTER(Commit, tree_id),
GETTER(Commit, parents),
{NULL}
};
Expand Down
4 changes: 3 additions & 1 deletion test/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from __future__ import unicode_literals
import unittest

from pygit2 import GIT_OBJ_COMMIT, Signature
from pygit2 import GIT_OBJ_COMMIT, Signature, Oid
from . import utils


Expand Down Expand Up @@ -92,6 +92,7 @@ def test_new_commit(self):
self.assertEqualSignature(committer, commit.committer)
self.assertEqualSignature(author, commit.author)
self.assertEqual(tree, commit.tree.hex)
self.assertEqual(Oid(hex=tree), commit.tree_id)
self.assertEqual(1, len(commit.parents))
self.assertEqual(COMMIT_SHA, commit.parents[0].hex)

Expand All @@ -118,6 +119,7 @@ def test_new_commit_encoding(self):
self.assertEqualSignature(committer, commit.committer)
self.assertEqualSignature(author, commit.author)
self.assertEqual(tree, commit.tree.hex)
self.assertEqual(Oid(hex=tree), commit.tree_id)
self.assertEqual(1, len(commit.parents))
self.assertEqual(COMMIT_SHA, commit.parents[0].hex)

Expand Down
0