Upgrading to libgit2 0.19 (wip)
Removed: - Remote.fetchspec Added: - Remote.refspec_count - Remote.get_refspec(n)
This commit is contained in:
@@ -12,6 +12,7 @@ The Remote type
|
|||||||
|
|
||||||
.. autoattribute:: pygit2.Remote.name
|
.. autoattribute:: pygit2.Remote.name
|
||||||
.. autoattribute:: pygit2.Remote.url
|
.. autoattribute:: pygit2.Remote.url
|
||||||
.. autoattribute:: pygit2.Remote.fetchspec
|
.. autoattribute:: pygit2.Remote.refspec_count
|
||||||
|
.. automethod:: pygit2.Remote.get_refspec
|
||||||
.. automethod:: pygit2.Remote.fetch
|
.. automethod:: pygit2.Remote.fetch
|
||||||
.. automethod:: pygit2.Remote.save
|
.. automethod:: pygit2.Remote.save
|
||||||
|
67
src/remote.c
67
src/remote.c
@@ -125,57 +125,41 @@ Remote_url__set__(Remote *self, PyObject* py_url)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PyDoc_STRVAR(Remote_fetchspec__doc__,
|
PyDoc_STRVAR(Remote_refspec_count__doc__, "Number of refspecs.");
|
||||||
"= (source:str, destination:str)\n"
|
|
||||||
"\n"
|
|
||||||
"Name of the remote source and destination fetch refspecs\n");
|
|
||||||
|
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
Remote_fetchspec__get__(Remote *self)
|
Remote_refspec_count__get__(Remote *self)
|
||||||
{
|
{
|
||||||
PyObject* py_tuple = NULL;
|
size_t count;
|
||||||
const git_refspec * refspec;
|
|
||||||
|
|
||||||
refspec = git_remote_fetchspec(self->remote);
|
count = git_remote_refspec_count(self->remote);
|
||||||
if (refspec != NULL) {
|
return PyLong_FromSize_t(count);
|
||||||
py_tuple = Py_BuildValue(
|
|
||||||
"(ss)",
|
|
||||||
git_refspec_src(refspec),
|
|
||||||
git_refspec_dst(refspec)
|
|
||||||
);
|
|
||||||
|
|
||||||
return py_tuple;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Error_set(GIT_ENOTFOUND);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
Remote_fetchspec__set__(Remote *self, PyObject* py_tuple)
|
PyDoc_STRVAR(Remote_get_refspec__doc__,
|
||||||
|
"get_refspec(n) -> (str, str)\n"
|
||||||
|
"\n"
|
||||||
|
"Return the refspec at the given position.");
|
||||||
|
|
||||||
|
PyObject *
|
||||||
|
Remote_get_refspec(Remote *self, PyObject *value)
|
||||||
{
|
{
|
||||||
int err;
|
size_t n;
|
||||||
size_t length = 0;
|
const git_refspec *refspec;
|
||||||
char* src = NULL, *dst = NULL, *buf = NULL;
|
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(py_tuple, "ss", &src, &dst))
|
n = PyLong_AsSize_t(value);
|
||||||
return -1;
|
if (PyErr_Occurred())
|
||||||
|
return NULL;
|
||||||
|
|
||||||
/* length is strlen('+' + src + ':' + dst) and Null-Byte */
|
refspec = git_remote_get_refspec(self->remote, n);
|
||||||
length = strlen(src) + strlen(dst) + 3;
|
if (refspec == NULL) {
|
||||||
buf = (char*) calloc(length, sizeof(char));
|
PyErr_SetObject(PyExc_IndexError, value);
|
||||||
if (buf != NULL) {
|
return NULL;
|
||||||
sprintf(buf, "+%s:%s", src, dst);
|
|
||||||
err = git_remote_set_fetchspec(self->remote, buf);
|
|
||||||
free(buf);
|
|
||||||
|
|
||||||
if (err == GIT_OK)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
Error_set_exc(PyExc_ValueError);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return Py_BuildValue("(ss)", git_refspec_src(refspec),
|
||||||
|
git_refspec_dst(refspec));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -237,13 +221,14 @@ Remote_save(Remote *self, PyObject *args)
|
|||||||
PyMethodDef Remote_methods[] = {
|
PyMethodDef Remote_methods[] = {
|
||||||
METHOD(Remote, fetch, METH_NOARGS),
|
METHOD(Remote, fetch, METH_NOARGS),
|
||||||
METHOD(Remote, save, METH_NOARGS),
|
METHOD(Remote, save, METH_NOARGS),
|
||||||
|
METHOD(Remote, get_refspec, METH_O),
|
||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
PyGetSetDef Remote_getseters[] = {
|
PyGetSetDef Remote_getseters[] = {
|
||||||
GETSET(Remote, name),
|
GETSET(Remote, name),
|
||||||
GETSET(Remote, url),
|
GETSET(Remote, url),
|
||||||
GETSET(Remote, fetchspec),
|
GETTER(Remote, refspec_count),
|
||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -42,6 +42,7 @@
|
|||||||
/* Python 2 support */
|
/* Python 2 support */
|
||||||
#if PY_MAJOR_VERSION == 2
|
#if PY_MAJOR_VERSION == 2
|
||||||
#define PyLong_FromSize_t PyInt_FromSize_t
|
#define PyLong_FromSize_t PyInt_FromSize_t
|
||||||
|
#define PyLong_AsSize_t (size_t)PyInt_AsSsize_t
|
||||||
#define PyLong_AsLong PyInt_AsLong
|
#define PyLong_AsLong PyInt_AsLong
|
||||||
#undef PyLong_Check
|
#undef PyLong_Check
|
||||||
#define PyLong_Check PyInt_Check
|
#define PyLong_Check PyInt_Check
|
||||||
|
@@ -75,16 +75,18 @@ class RepositoryTest(utils.RepoTestCase):
|
|||||||
self.assertRaisesAssign(ValueError, remote, 'url', '')
|
self.assertRaisesAssign(ValueError, remote, 'url', '')
|
||||||
|
|
||||||
|
|
||||||
def test_remote_fetchspec(self):
|
def test_refspec(self):
|
||||||
remote = self.repo.remotes[0]
|
remote = self.repo.remotes[0]
|
||||||
|
|
||||||
self.assertEqual(REMOTE_FETCHSPEC_SRC, remote.fetchspec[0])
|
self.assertEqual(remote.refspec_count, 1)
|
||||||
self.assertEqual(REMOTE_FETCHSPEC_DST, remote.fetchspec[1])
|
refspec = remote.get_refspec(0)
|
||||||
|
self.assertEqual(refspec[0], REMOTE_FETCHSPEC_SRC)
|
||||||
|
self.assertEqual(refspec[1], REMOTE_FETCHSPEC_DST)
|
||||||
|
|
||||||
new_fetchspec = ('refs/foo/*', 'refs/remotes/foo/*')
|
# new_fetchspec = ('refs/foo/*', 'refs/remotes/foo/*')
|
||||||
remote.fetchspec = new_fetchspec
|
# remote.fetchspec = new_fetchspec
|
||||||
self.assertEqual(new_fetchspec[0], remote.fetchspec[0])
|
# self.assertEqual(new_fetchspec[0], remote.fetchspec[0])
|
||||||
self.assertEqual(new_fetchspec[1], remote.fetchspec[1])
|
# self.assertEqual(new_fetchspec[1], remote.fetchspec[1])
|
||||||
|
|
||||||
|
|
||||||
def test_remote_list(self):
|
def test_remote_list(self):
|
||||||
|
Reference in New Issue
Block a user