Fix prefix handling in ref iteration functions
commitb3cfc4066d87476726e8711a8b5fc3b721aba41c
authorJosh Triplett <josh@joshtriplett.org>
Tue, 5 Jul 2011 17:54:21 +0000 (5 10:54 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 6 Jul 2011 18:12:01 +0000 (6 11:12 -0700)
treeece11d91ef62e7704263d93b67978d36fe03db27
parent5df3e2b3ca5ebe8123927a81d682993ad597a584
Fix prefix handling in ref iteration functions

The do_for_each_ref iteration function accepts a prefix and a trim, and
checks for the prefix on each ref before passing in that ref; it also
supports trimming off part of the ref before passing it.  However,
do_for_each_ref used trim as the length of the prefix to check, ignoring
the actual length of the prefix.  Switch to using prefixcmp, checking
the entire length of the prefix string, to properly support a trim value
different than the length of the prefix.

Several callers passed a prefix of "refs/" to filter out everything
outside of refs/, but a trim of 0 to avoid trimming off the "refs/"; the
trim of 0 meant that the filter of "refs/" no longer applied.  Change
these callers to pass an empty prefix instead, to avoid changing the
existing behavior.  Various callers count on this lack of filtering,
such as receive-pack which uses add_extra_ref to add alternates as refs
named ".have"; adding filtering would break that, causing
t5501-fetch-push-alternates.sh to fail.  That lack of filtering doesn't
currently have any other effect, since the loose ref functions can never
supply refs outside of "refs/", and packed-refs will not normally
include such refs unless manually edited.

Signed-off-by: Josh Triplett <josh@joshtriplett.org>
Signed-off-by: Jamey Sharp <jamey@minilop.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs.c