Reference: deprecate get_object() in favour of peel()
Let Reference.peel()'s argument be optional, and default to GIT_OBJ_ANY, which mirrors the behaviour of get_object(). Since we reimplement the get_object() behaviour, change it to call peel() which makes sure we can keep using the old tests for this aspect.
This commit is contained in:
@@ -367,36 +367,35 @@ Reference_log(Reference *self)
|
|||||||
PyDoc_STRVAR(Reference_get_object__doc__,
|
PyDoc_STRVAR(Reference_get_object__doc__,
|
||||||
"get_object() -> object\n"
|
"get_object() -> object\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Retrieves the object the current reference is pointing to.");
|
"Retrieves the object the current reference is pointing to.\n"
|
||||||
|
"\n"
|
||||||
|
"This method is deprecated, please use Reference.peel() instead.");
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
Reference_get_object(Reference *self)
|
Reference_get_object(Reference *self)
|
||||||
{
|
{
|
||||||
int err;
|
return PyObject_CallMethod((PyObject *) self, "peel", NULL);
|
||||||
git_object* obj;
|
|
||||||
|
|
||||||
CHECK_REFERENCE(self);
|
|
||||||
|
|
||||||
err = git_reference_peel(&obj, self->reference, GIT_OBJ_ANY);
|
|
||||||
if (err < 0)
|
|
||||||
return Error_set(err);
|
|
||||||
|
|
||||||
return wrap_object(obj, self->repo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(Reference_peel__doc__,
|
PyDoc_STRVAR(Reference_peel__doc__,
|
||||||
"peel(type) -> object\n"
|
"peel(type=None) -> object\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Retrieve an object of the given type by recursive peeling.");
|
"Retrieve an object of the given type by recursive peeling.\n"
|
||||||
|
"\n"
|
||||||
|
"If no type is provided, the first non-tag object will be returned.");
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
Reference_peel(Reference *self, PyObject *py_type)
|
Reference_peel(Reference *self, PyObject *args)
|
||||||
{
|
{
|
||||||
int err, type;
|
int err, type;
|
||||||
git_object *obj;
|
git_object *obj;
|
||||||
|
PyObject *py_type = Py_None;
|
||||||
|
|
||||||
CHECK_REFERENCE(self);
|
CHECK_REFERENCE(self);
|
||||||
|
|
||||||
|
if (!PyArg_ParseTuple(args, "|O", &py_type))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
type = py_object_to_object_type(py_type);
|
type = py_object_to_object_type(py_type);
|
||||||
if (type == -1)
|
if (type == -1)
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -502,7 +501,7 @@ PyMethodDef Reference_methods[] = {
|
|||||||
METHOD(Reference, log, METH_NOARGS),
|
METHOD(Reference, log, METH_NOARGS),
|
||||||
METHOD(Reference, get_object, METH_NOARGS),
|
METHOD(Reference, get_object, METH_NOARGS),
|
||||||
METHOD(Reference, set_target, METH_VARARGS | METH_KEYWORDS),
|
METHOD(Reference, set_target, METH_VARARGS | METH_KEYWORDS),
|
||||||
METHOD(Reference, peel, METH_O),
|
METHOD(Reference, peel, METH_VARARGS),
|
||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -181,6 +181,9 @@ py_object_to_object_type(PyObject *py_type)
|
|||||||
{
|
{
|
||||||
int type = -1;
|
int type = -1;
|
||||||
|
|
||||||
|
if (py_type == Py_None)
|
||||||
|
return GIT_OBJ_ANY;
|
||||||
|
|
||||||
if (PyLong_Check(py_type)) {
|
if (PyLong_Check(py_type)) {
|
||||||
type = PyLong_AsLong(py_type);
|
type = PyLong_AsLong(py_type);
|
||||||
if (type == -1 && PyErr_Occurred())
|
if (type == -1 && PyErr_Occurred())
|
||||||
|
Reference in New Issue
Block a user