Util.pm: add read_HEAD_ref function
The read_HEAD_symref function returns undef for both a detached
HEAD and for an invalid or missing HEAD.
Sometimes it's necessary to deal with a detached HEAD.
Rework read_HEAD_symref into read_HEAD_ref so that it will also
return a valid detached HEAD (as an all lowercased hex string).
Reimplement a new read_HEAD_symref in terms of read_HEAD_ref to
retain the old semantics for all existing callers.
Additionally, incorporate some of the basic checks for invalid
ref name characters mentioned in `git help check-ref-format` to
provide some extra validation.
Signed-off-by: Kyle J. McKay <mackyle@gmail.com>