def _make_determine_wants_func(ref_mutator):
    """Returns a safer version of ref_mutator, suitable for passing as the
    determine_wants argument to dulwich's send_pack method. The returned
    function will not delete or modify any existing refs."""
    def determine_wants(old_refs):
        refs = {k.decode('UTF-8'): v.decode('UTF-8') for k, v in old_refs.items()}
        new_refs = ref_mutator(refs)
        new_refs = {k.encode('UTF-8'): v.encode('UTF-8') for k, v in new_refs.items()}
        new_refs.update(old_refs)  # Make sure we don't delete/modify anything.
        return new_refs
    return determine_wants