for-each-ref: refactor refname handling