So, I would be tempted to allow `git_pathspec_match_path` to take a NULL pointer for `matched_pathspec` and only assign to it if the pointer is non-NULL. This would remove the need for throwaway local variables in `index.c` and `checkout.c` where the matched pathspec return value does not matter to you. 

Also, you could put a single `if (matched_pathspec) *matched_pathspec = NULL;` at the top of the function and then only overwrite the value if/when a match is found so you don't have to clear the value in two different places - although, frankly that's a matter of preference and I don't feel too strongly, if you like the existing way better.