'Handle the head of a \'git-receive-pack\' request.
:param proto: Protocol object to read from
:param capabilities: List of negotiated capabilities
:param old_refs: Old refs, as received from the server
:param new_refs: Refs to change
:return: (have, want) tuple'

def _handle_receive_pack_head(self, proto, capabilities, old_refs, new_refs):

    want = []
    have = [x for x in old_refs.values() if (not (x == ZERO_SHA))]
    sent_capabilities = False
    for refname in new_refs:
        if (not isinstance(refname, bytes)):
            raise TypeError(('refname    is    not    a    bytestring:    %r' % refname))
        old_sha1 = old_refs.get(refname, ZERO_SHA)
        if (not isinstance(old_sha1, bytes)):
            raise TypeError(('old    sha1    for    %s    is    not    a    bytestring:    %r' % (refname, old_sha1)))
        new_sha1 = new_refs.get(refname, ZERO_SHA)
        if (not isinstance(new_sha1, bytes)):
            raise TypeError(('old    sha1    for    %s    is    not    a    bytestring    %r' % (refname, new_sha1)))
        if (old_sha1 != new_sha1):
            if sent_capabilities:
                proto.write_pkt_line(((((old_sha1 + '    ') + new_sha1) + '    ') + refname))
            else:
                proto.write_pkt_line(((((((old_sha1 + '    ') + new_sha1) + '    ') + refname) + '\x00') + '    '.join(capabilities)))
                sent_capabilities = True
        if ((new_sha1 not in have) and (new_sha1 != ZERO_SHA)):
            want.append(new_sha1)
    proto.write_pkt_line(None)
    return (have, want)
