From d798d95a8b821d8d47a993309afe6b0df275e2ad Mon Sep 17 00:00:00 2001 From: Nico von Geyso Date: Sat, 16 Feb 2013 21:26:51 +0100 Subject: [PATCH] added basic fetch()-method for remotes --- src/remote.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/remote.c b/src/remote.c index 09bc847..6b706d9 100644 --- a/src/remote.c +++ b/src/remote.c @@ -174,6 +174,47 @@ Remote_fetchspec__set__(Remote *self, PyObject* py_tuple) } +PyDoc_STRVAR(Remote_fetch__doc__, + "fetch() -> {'indexed_objects': int, 'received_objects' : int," + " 'received_bytesa' : int}\n" + "\n" + "Negotiate what objects should be downloaded and download the\n" + "packfile with those objects"); + +PyObject * +Remote_fetch(Remote *self, PyObject *args) +{ + PyObject* py_stats; + const git_transfer_progress *stats; + int err; + + err = git_remote_connect(self->remote, GIT_DIRECTION_FETCH); + if (err == GIT_OK) { + err = git_remote_download(self->remote, NULL, NULL); + if (err == GIT_OK) { + stats = git_remote_stats(self->remote); + py_stats = Py_BuildValue("{s:i,s:i,s:i}", + "indexed_objects", stats->indexed_objects, + "received_objects", stats->received_objects, + "received_bytes", stats->received_bytes); + + err = git_remote_update_tips(self->remote); + } + git_remote_disconnect(self->remote); + } + + if (err < 0) + return Error_set(err); + + return (PyObject*) py_stats; +} + + +PyMethodDef Remote_methods[] = { + METHOD(Remote, fetch, METH_NOARGS), + {NULL} +}; + PyGetSetDef Remote_getseters[] = { GETSET(Remote, name), GETSET(Remote, url), @@ -211,7 +252,7 @@ PyTypeObject RemoteType = { 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ - 0, /* tp_methods */ + Remote_methods, /* tp_methods */ 0, /* tp_members */ Remote_getseters, /* tp_getset */ 0, /* tp_base */