for-each-ref: extract helper functions out of grab_single_ref()
for-each-ref: extract helper functions out of grab_single_ref()

Extract two helper functions out of grab_single_ref(). Firstly,
new_refinfo() which is used to allocate memory for a new refinfo
structure and copy the objectname, refname and flag to it.
Secondly, match_name_as_path() which when given an array of patterns
and the refname checks if the refname matches any of the patterns
given while the pattern is a pathname, also supports wildcard
characters.

This is a preperatory patch for restructuring 'for-each-ref' and
eventually moving most of it to 'ref-filter' to provide the
functionality to similar commands via public API's.

Helped-by: Junio C Hamano <a6723cc3f76163bf7adb636a73ac3b0ceb3e6b9b@pobox.com>
Mentored-by: Christian Couder <58cc993db606fd7043084d51c23db751557f1001@gmail.com>
Mentored-by: Matthieu Moy <fbbe566372a364dbd17bce4222f8e1855291903f@grenoble-inp.fr>
Signed-off-by: Karthik Nayak <f21e23168db91f2bd3ec812184a2ac51d05a196a@gmail.com>
Reviewed-by: Matthieu Moy <d4d2cc2a6ec7b2aa587d4887cc5ed200f9b685a1@imag.fr>
Signed-off-by: Junio C Hamano <a6723cc3f76163bf7adb636a73ac3b0ceb3e6b9b@pobox.com>

destenson/git,destenson/git,destenson/git,destenson/git,destenson/git,destenson/git,destenson/git,destenson/git