hgext/simple4server.py
author Pierre-Yves David <pierre-yves.david@fb.com>
Fri, 28 Feb 2014 13:45:59 -0800
changeset 826 bee5e1105e6c
parent 822 5f5d269278e9
child 852 aa722de36179
permissions -rw-r--r--
exchange: add the pullmarker wireproto command to simple4server This will allow simple server side support. (yes, code duplication is bad I already told you I won't do it too much mom)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
660
e6e47c432ffd hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     1
'''enable experimental obsolescence feature of Mercurial
e6e47c432ffd hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     2
e6e47c432ffd hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     3
OBSOLESCENCE IS AN EXPERIMENTAL FEATURE MAKE SURE YOU UNDERSTOOD THE INVOLVED
e6e47c432ffd hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     4
CONCEPT BEFORE USING IT.
e6e47c432ffd hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     5
e6e47c432ffd hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     6
/!\ THIS EXTENSION IS INTENDED FOR SERVER SIDE ONLY USAGE /!\
e6e47c432ffd hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     7
e6e47c432ffd hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     8
For client side usages it is recommended to use the evolve extension for
e6e47c432ffd hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     9
improved user interface.'''
e6e47c432ffd hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    10
e6e47c432ffd hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    11
import mercurial.obsolete
e6e47c432ffd hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    12
mercurial.obsolete._enabled = True
822
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    13
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    14
from mercurial import wireproto
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    15
from mercurial import extension
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    16
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    17
def srv_pushobsmarkers(repo, proto):
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    18
    """wireprotocol command"""
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    19
    fp = StringIO()
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    20
    proto.redirect()
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    21
    proto.getfile(fp)
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    22
    data = fp.getvalue()
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    23
    fp.close()
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    24
    lock = repo.lock()
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    25
    try:
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    26
        tr = repo.transaction('pushkey: obsolete markers')
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    27
        try:
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    28
            repo.obsstore.mergemarkers(tr, data)
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    29
            tr.close()
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    30
        finally:
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    31
            tr.release()
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    32
    finally:
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    33
        lock.release()
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    34
    return wireproto.pushres(0)
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    35
826
bee5e1105e6c exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 822
diff changeset
    36
def srv_pullobsmarkers(repo, proto, others):
bee5e1105e6c exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 822
diff changeset
    37
    opts = wireproto.options('', ['heads', 'common'], others)
bee5e1105e6c exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 822
diff changeset
    38
    for k, v in opts.iteritems():
bee5e1105e6c exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 822
diff changeset
    39
        if k in ('heads', 'common'):
bee5e1105e6c exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 822
diff changeset
    40
            opts[k] = wireproto.decodelist(v)
bee5e1105e6c exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 822
diff changeset
    41
    obsdata = _getobsmarkersstream(repo, **opts)
bee5e1105e6c exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 822
diff changeset
    42
    length = '%20i' % len(obsdata.getvalue())
bee5e1105e6c exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 822
diff changeset
    43
    def data():
bee5e1105e6c exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 822
diff changeset
    44
        yield length
bee5e1105e6c exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 822
diff changeset
    45
        for c in proto.groupchunks(obsdata):
bee5e1105e6c exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 822
diff changeset
    46
            yield c
bee5e1105e6c exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 822
diff changeset
    47
    return wireproto.streamres(data())
bee5e1105e6c exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 822
diff changeset
    48
822
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    49
def capabilities(orig, repo, proto):
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    50
    """wrapper to advertise new capability"""
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    51
    caps = orig(repo, proto)
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    52
    if obsolete._enabled:
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    53
        caps += ' _evoext_pushobsmarkers_0'
826
bee5e1105e6c exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 822
diff changeset
    54
        caps += ' _evoext_pullobsmarkers_0'
822
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    55
    return caps
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    56
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    57
def extsetup(ui):
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    58
    wireproto.commands['evoext_pushobsmarkers_0'] = (srv_pushobsmarkers, '')
826
bee5e1105e6c exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 822
diff changeset
    59
    wireproto.commands['evoext_pullobsmarkers_0'] = (srv_pullobsmarkers, '*')
822
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    60
    extensions.wrapfunction(wireproto, 'capabilities', capabilities)