Extract this function out of the rev-parse code to be able to DWIM a reference instead of its target.