libgit2/libgit2 — pull request #910 by arrbee (2012-08-30 21:32:12+00:00)
Title: Diff iterators

This refactors the diff output code so that an iterator object can be used to traverse and generate the diffs, instead of just the `foreach()` style API with callbacks. The code has been rearranged so that the two styles can still share most functions.

This also replaces `GIT_REVWALKOVER` with `GIT_ITEROVER` and uses that as a common error code for marking the end of iteration when using a iterator style of object. Also, I try to call `giterr_clear()` before returning that code, so there won't be a lingering inaccurate error message.

For the tests, in addition to new tests of the iterator code, I wrote a version of `git_diff_foreach()` that is based on the iterators just for testing purposes. It is in `diff_helpers.c` and has the exact same interface as the regular foreach. Then I went in to some of the existing `git_diff_foreach` tests and made them run twice - once with the regular public API and once with the iterator-based version.

Please note: I don't want to replace the regular foreach with the iterator based version because the iterators need to keep a bunch of stuff in memory and so the classic foreach API is more memory efficient. I refactored the old code so that the foreach API and the iterator API could avoid most code duplication, so I don't feel back about not basing foreach on the iterator.