Implement remotes via CFFI #360
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.EDIT: there is a way to raise an exception with an old stack trace, but the python 2 version (three-argument raise) causes a syntax error in python 3 even if we're never going to call the code.
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 aTransferProgressobject instead of a dict with a few values from said struct. AFAIU thefetch()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.