Improve ignore handling in git_status_file

The git_status_file API was doing a hack to deal with files that
are inside ignored directories.  The status scan was not reporting
any file in this case, so git_status_file would attempt a final
"stat()" call, and return IGNORED if the file actually existed.

On case-insensitive filesystems where core.ignorecase is set
incorrectly, this magic check can "succeed" and report a file
as ignored when it should actually return ENOTFOUND.

Now that we have the GIT_STATUS_OPT_RECURSE_IGNORED_DIRS, we can
use that flag to make sure that git_status_file() will look into
ignored directories and eliminate the hack completely, so we give
the correct error.
Fix diff output for renames and copies

If you use rename detection, the renamed and copied files would
not show any text diffs because the function that decides if
data should be loaded didn't know which sides of the diff to
load for those cases.

This adds a test that looks at the patch generated for diff
entries that are COPIED or RENAMED.
Merge pull request #1573 from nulltoken/fix/leaks

Fix some memory leaks
Merge pull request #1572 from arrbee/diff-patch-with-rename

Fix diff output for renames and copies
Merge pull request #1571 from arrbee/what-if-ignorecase-lies

Improve ignore handling in git_status_file
refs: introduce an iterator

This allows us to get a list of reference names in a loop instead of callbacks.
refdb_fs: don't crash when the repo doesn't have a path
Make sure the ref iterator works in an repo without physical presence
Remove outdated test

Selecting wether to list loose or packed references is not something
we want to support anymore, so remove a test for this.
Add iterator support to the testdb backend
refs: implement _foreach with the iterator
refs: remove the OID/SYMBOLIC filtering

Nobody should ever be using anything other than ALL at this level, so
remove the option altogether.

As part of this, git_reference_foreach_glob is now implemented in the
frontend using an iterator. Backends will later regain the ability of
doing the glob filtering in the backend.
Move a couple more functions to use iterators
Introduce a glob-filtering iterator

If the backend doesn't provide support for it, the matching is done in
refdb on top of a normal iterator.
Merge pull request #1385 from carlosmn/refs-iter

Introduce a refs iterator
Fix broken build when MSVC SDL checks is enabled
Merge pull request #1569 from linquize/msvc-sdl

Fix broken build when MSVC SDL checks is enabled
Fix refdb iteration early termination bug

There was a problem found in the Rugged test suite where the
refdb_fs_backend__next function could exit too early in some
very specific hashing patterns for packed refs.  This ports
the Rugged test to libgit2 and then fixes the bug.
Merge pull request #1575 from arrbee/ref-iterator-early-exit

Fix refdb iteration early termination bug
CMake: don't try to use bundled zlib when the system's path is in the cache

The code surrounding zlib bundling did not take into consideration
that ZLIB_LIBRARY gets cached, and assumed that FIND(ZLIB) would
always set ZLIB_FOUND, which does not hold true, as this variable
signifies that we have found the package and had to look at the
system, as its location was not cached.

Only use the bundled sources if the external zlib is neither
newly-found nor cached.