libgit2/pygit2 — pull request #360 by carlosmn (2014-04-17 21:46:53+00:00)
Title: Implement remotes via CFFI

As the cffi module allows us to use python instead of C, which reduces the line count and boilerplate (not to mention python > C in general), let's start integrating this library by using it for the remotes. Remotes are IO-bound operations and essentially all of the work is done by libgit2, so the reduction in performance which can be seen in the revwalk PoC would be minimal here.

Unfortunately due to the need to copy the C declarations, which are provided by libgit2's headers for the C extension, the reduction in line count isn't as large as I would have hoped, but consider that there's ~300 lines which don't really add anything, and there's even extra documentation for the callbacks. Adding more functionality will be able to re-use a bunch of these declarations, so we should see even better results there.

As cffi cannot carry exceptions across the C layer, the re-raised exception would now have a wrong stacktrace. I'm not sure if there is a way to re-raise an exception in a way that keeps the old stack trace.

I've reworked some of the common code from the PoC so that we keep compatibility with Python 2.6 as it didn't take much effort.

This PR does introduce a slight change. `Remote.fetch()` now returns a `TransferProgress` object instead of a dict with a few values from said struct. AFAIU the `fetch()` method came before we exposed TransferProgress, which is why it uses its own type. We would want to make this change at some point soon anyway, but I can switch to the one in master if we want to wait for a non-patch release to change that.