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:
Carlos Martín Nieto 2014-10-10 11:36:37 +02:00
parent 59da03476e
commit 5d4c955d25
2 changed files with 17 additions and 15 deletions

View File

@ -367,36 +367,35 @@ Reference_log(Reference *self)
PyDoc_STRVAR(Reference_get_object__doc__,
"get_object() -> object\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 *
Reference_get_object(Reference *self)
{
int err;
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);
return PyObject_CallMethod((PyObject *) self, "peel", NULL);
}
PyDoc_STRVAR(Reference_peel__doc__,
"peel(type) -> object\n"
"peel(type=None) -> object\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 *
Reference_peel(Reference *self, PyObject *py_type)
Reference_peel(Reference *self, PyObject *args)
{
int err, type;
git_object *obj;
PyObject *py_type = Py_None;
CHECK_REFERENCE(self);
if (!PyArg_ParseTuple(args, "|O", &py_type))
return NULL;
type = py_object_to_object_type(py_type);
if (type == -1)
return NULL;
@ -502,7 +501,7 @@ PyMethodDef Reference_methods[] = {
METHOD(Reference, log, METH_NOARGS),
METHOD(Reference, get_object, METH_NOARGS),
METHOD(Reference, set_target, METH_VARARGS | METH_KEYWORDS),
METHOD(Reference, peel, METH_O),
METHOD(Reference, peel, METH_VARARGS),
{NULL}
};

View File

@ -181,6 +181,9 @@ py_object_to_object_type(PyObject *py_type)
{
int type = -1;
if (py_type == Py_None)
return GIT_OBJ_ANY;
if (PyLong_Check(py_type)) {
type = PyLong_AsLong(py_type);
if (type == -1 && PyErr_Occurred())