tag: add get_object() method
This maps to git_tag_peel().
This commit is contained in:
parent
5a007802d0
commit
298f941036
@ -267,6 +267,8 @@ A tag is a static label for a commit. See references for more information.
|
||||
.. autoattribute:: pygit2.Tag.tagger
|
||||
.. autoattribute:: pygit2.Tag.message
|
||||
|
||||
.. automethod:: pygit2.Tag.get_object
|
||||
|
||||
|
||||
Creating tags
|
||||
--------------------
|
||||
|
27
src/tag.c
27
src/tag.c
@ -27,6 +27,7 @@
|
||||
|
||||
#define PY_SSIZE_T_CLEAN
|
||||
#include <Python.h>
|
||||
#include "object.h"
|
||||
#include "error.h"
|
||||
#include "types.h"
|
||||
#include "utils.h"
|
||||
@ -47,6 +48,25 @@ Tag_target__get__(Tag *self)
|
||||
}
|
||||
|
||||
|
||||
PyDoc_STRVAR(Tag_get_object__doc__,
|
||||
"get_object() -> object\n"
|
||||
"\n"
|
||||
"Retrieves the object the current reference is pointing to.");
|
||||
|
||||
PyObject *
|
||||
Tag_get_object(Tag *self)
|
||||
{
|
||||
int err;
|
||||
git_object* obj;
|
||||
|
||||
err = git_tag_peel(&obj, self->tag);
|
||||
if (err < 0)
|
||||
return Error_set(err);
|
||||
|
||||
return wrap_object(obj, self->repo);
|
||||
}
|
||||
|
||||
|
||||
PyDoc_STRVAR(Tag_name__doc__, "Tag name.");
|
||||
|
||||
PyObject *
|
||||
@ -94,6 +114,11 @@ Tag__message__get__(Tag *self)
|
||||
return PyBytes_FromString(git_tag_message(self->tag));
|
||||
}
|
||||
|
||||
PyMethodDef Tag_methods[] = {
|
||||
METHOD(Tag, get_object, METH_NOARGS),
|
||||
{NULL}
|
||||
};
|
||||
|
||||
PyGetSetDef Tag_getseters[] = {
|
||||
GETTER(Tag, target),
|
||||
GETTER(Tag, name),
|
||||
@ -134,7 +159,7 @@ PyTypeObject TagType = {
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
Tag_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
Tag_getseters, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
|
@ -89,6 +89,11 @@ class TagTest(utils.BareRepoTestCase):
|
||||
self.assertRaises(AttributeError, setattr, tag, 'tagger', tagger)
|
||||
self.assertRaises(AttributeError, setattr, tag, 'message', message)
|
||||
|
||||
def test_get_object(self):
|
||||
repo = self.repo
|
||||
tag = repo[TAG_SHA]
|
||||
self.assertEqual(repo[tag.target].oid, tag.get_object().oid)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user