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.

I tried to find existing test data that would recreate the bug and I wasn't able to - it relies on a particular pattern of ref names being inserted into the hash, so this was the best way to get known failing test data.

/cc @carlosnm