WIP: cleanup naming... refs.c: Add rules for resolving refs using remote refspecs

The "$remote/$branch" expression is often used as a shorthand with the
intention of referring to the remote-tracking branch corresponding to
the given $branch in the $remote repo.

Currently, Git resolves this by prepending "refs/remotes/" to the given
"$remote/$branch" expression, resulting in "refs/remotes/$remote/$branch",
which is equivalent to the above intention only when conventional
refspecs are being used (e.g. refs/heads/*:refs/remotes/origin/*).

If unconventional refspecs (e.g. refs/heads/*:refs/remotes/origin/heads/*)
are being used, then the current expansion ("refs/remotes/$remote/$branch")
fails to match the remote-tracking branches from the configured remotes.

Instead of doing a pure textual expansion (from "$remote/$branch" to
"refs/remotes/$remote/$branch"), we should find all remotes matching
"$remote", look up their fetch refspecs, and map "refs/heads/$branch"
through them to find the appropriate remote-tracking branch name
corresponding to "$remote/$branch". This would yield the correct
remote-tracking branch in all cases, both for conventional and
unconventional refspecs.

Currently the textual expansion of shorthand refs is encoded in the
ref_rev_parse_rules list of expansion patterns in refs.c. In order to
move beyond textual expansion, we need to encode the method of expansion
along with the expansion pattern itself.

This patch introduces ref_rev_parse_rules_alt, which encodes both an
expansion pattern, and a corresponding expansion function that are
called (with the pattern as one of the arguments) to perform the actual
expansion of the shorthand ref. This allows for more than just textual
expansion to be done, by specifying an appropriate expansion function.

Along with the ref_rev_parse_rules_alt list, we introduce two expansion
functions: match_ref_pattern() - which performs the same textual
substitution as before, and match_remote_refspec() - which performs the
remote refspec traversal described above.

Implementing the proper expansion of "$remote/$branch" is now a simple
matter of adding another entry to the ref_rev_parse_rules_alt list,
using the match_remote_refspec() expansion function.

Note that the  existing "refs/remotes/*" textual expansion is kept to
preserve backwards compatibility for refs under refs/remotes/* that are
not covered by any configured refspec.

Finally, there are currently no users of the new ref_rev_parse_rules_alt
list, but users of ref_rev_parse_rules will be converted in subsequent
patches.

Signed-off-by: Johan Herland <johan@herland.net>
WIP: refs.c: Teach dwim_ref() to use ref_rev_parse_rules_alt

FIXME: More tests!

Signed-off-by: Johan Herland <johan@herland.net>
WIP: refs.c: Teach dwim_log() to use ref_rev_parse_rules_alt

FIXME: Tests!

Signed-off-by: Johan Herland <johan@herland.net>
WIP: refs.c: Teach refname_match() to use ref_rev_parse_rules_alt

FIXME: Tests!

refname_match() is used to test whether "abbrev_name" is equivalent to
"full_name" under a given set of "rules". In all callers of this function,
the rules are always set to ref_rev_parse_rules, so instead of exporting
ref_rev_parse_rules_alt (and consequently struct ref_rev_parse_rule) to
cache.h, we instead simply remove the "rules" argument instead.

Signed-off-by: Johan Herland <johan@herland.net>
fixup! WIP: cleanup naming... refs.c: Add rules for resolving refs using remote refspecs
fixup! WIP: refs.c: Teach dwim_ref() to use ref_rev_parse_rules_alt
fixup! WIP: refs.c: Teach dwim_log() to use ref_rev_parse_rules_alt
fixup! WIP: refs.c: Teach refname_match() to use ref_rev_parse_rules_alt