As a small optimization, if `iter->glob` is non-NULL, you could pass it through `git_pathspec_prefix()` (you'd have to either make a temporary length=1 strarray or refactor that code) and use the result string for the last two parameters to the iterator instead of NULL. This would narrow the range of items that the iterator returns and avoid traversing excluded filesystem entries.

For example, if the glob was `refs/heads/vmg/*` then this change would avoid having the filesystem iterator look at (and `stat`) anything except the contents of the `refs/` directory, the `heads/` directory and everything below the `vmg/` directory. Plus, in the future, I hope to make the code even more efficient (avoiding extra `stat` calls) when you give a path prefix to the filesystem iterator.