libgit2/libgit2 — pull request #578 by arrbee (2012-02-29 01:38:34+00:00)
Title: Implementation of diff using iterators

I've rewritten the earlier diff pull request to use the git iterators and built out the functions for all of the various diff APIs (tree-to-tree, index-to-tree, workdir-to-tree, workdir-to-index) plus added the ability to take two diffs and merge them into a unified one (which is needed to implement `git diff `).

I expanded the capabilities of the `examples/diff.c` file to the point where it can emulate most of the regular command line version of `git diff`. I have tried it on various example repositories, but since it is so much like the regular command line diff, we can now go through and test it more broadly.

I reorganized the code a little bit, too. The diff list generators are now in `src/diff.c` and the `git_diff_foreach` and various output helper functions are all in `src/diff_output.c`.

I've tested this on Windows and it builds and the tests pass.

I haven't yet run valgrind to see if I missed freeing any memory allocations. I'll do that along with resolving any other comments that folks might have.

There are also a few TODOs left scattered in the code. These include various optimizations that I'm not yet doing (such as not trying to calculate the SHA of binary files in the work dir that look like they are changed). Also, I have not yet implemented rename detection and we will need to blend in support for filters (i.e. the CRLF stuff) for diff to work properly on all platforms), but there code is written so that there is a logical place for these things to be added.