libgit2/libgit2 — pull request #1413 by arrbee (2013-03-14 21:04:38+00:00)
Title: Further tree_iterator refactoring

The main goal of this PR is to further improve the `tree_iterator` internals. The main things it does are:

- [x] Keep `tree_iterator_entry` objects as pointers so we can use `git__tsort_r` on them
- [x] Allocate those entries using a `git_pool` to keep memory allocations low
- [x] Make `tree_iterator_entry` store pointers to the data it needs instead of index values into arrays so data access is more direct and efficient
- [x] Use `git__bsearch` to find the start of each tree frame when range limited
- [x] Use `git_path_cmp` explicitly for path comparisons instead of reimplementing it

I added a new `git_pool_free_array()` API to `git_pool`s so that I could efficiently free the entries array of `tree_iterator_entry` objects. This should result in half the work compared to calling `git_pool_free()` in a loop. (And I added tests for the free list functionality of `git_pool`s that was not previously being tested.)

After getting that stuff wrapped up, I ran this through valgrind and fixed a number issues flagged there - mostly small stuff, but one notable thing:

While running under valgrind on my machine, some `mmap()` calls would fail which would cause some diff tests to fail. Since I already had code to read a file into memory without `mmap()` (for the cases where we need to apply crlf filters), I rearranged the code a little bit and now fall back on reading the file into allocated memory if the attempt to `mmap()` the file fails.