for-each-ref: refactor get_short_ref function