hgext/simple4server.py
changeset 963 f80e8e3c3726
parent 888 097ddcb0da25
child 1067 5d063fed9e3d
equal deleted inserted replaced
962:d04a52f40f41 963:f80e8e3c3726
     6 /!\ THIS EXTENSION IS INTENDED FOR SERVER SIDE ONLY USAGE /!\
     6 /!\ THIS EXTENSION IS INTENDED FOR SERVER SIDE ONLY USAGE /!\
     7 
     7 
     8 For client side usages it is recommended to use the evolve extension for
     8 For client side usages it is recommended to use the evolve extension for
     9 improved user interface.'''
     9 improved user interface.'''
    10 
    10 
    11 testedwith = '2.9.1'
    11 testedwith = '3.0.1'
    12 buglink = 'https://bitbucket.org/marmoute/mutable-history/issues'
    12 buglink = 'https://bitbucket.org/marmoute/mutable-history/issues'
    13 
    13 
    14 import mercurial.obsolete
    14 import mercurial.obsolete
    15 mercurial.obsolete._enabled = True
    15 mercurial.obsolete._enabled = True
    16 
    16 
    20 from mercurial import extensions
    20 from mercurial import extensions
    21 from mercurial import obsolete
    21 from mercurial import obsolete
    22 from cStringIO import StringIO
    22 from cStringIO import StringIO
    23 from mercurial import node
    23 from mercurial import node
    24 from mercurial.hgweb import hgweb_mod
    24 from mercurial.hgweb import hgweb_mod
       
    25 from mercurial import bundle2
       
    26 from mercurial import localrepo
       
    27 from mercurial import exchange
    25 _pack = struct.pack
    28 _pack = struct.pack
       
    29 
       
    30 gboptslist = gboptsmap = None
       
    31 try:
       
    32     from mercurial import obsolete
       
    33     if not obsolete._enabled:
       
    34         obsolete._enabled = True
       
    35     from mercurial import wireproto
       
    36     gboptslist = getattr(wireproto, 'gboptslist', None)
       
    37     gboptsmap = getattr(wireproto, 'gboptsmap', None)
       
    38 except (ImportError, AttributeError):
       
    39     raise util.Abort('Your Mercurial is too old for this version of Evolve\n'
       
    40                      'requires version 3.0.1 or above')
    26 
    41 
    27 # Start of simple4server specific content
    42 # Start of simple4server specific content
    28 
    43 
    29 from mercurial import pushkey
    44 from mercurial import pushkey
    30 
    45 
   226     advertise = repo.ui.configbool('__temporary__', 'advertiseobsolete', True)
   241     advertise = repo.ui.configbool('__temporary__', 'advertiseobsolete', True)
   227     if obsolete._enabled and advertise:
   242     if obsolete._enabled and advertise:
   228         caps += ' _evoext_pushobsmarkers_0'
   243         caps += ' _evoext_pushobsmarkers_0'
   229         caps += ' _evoext_pullobsmarkers_0'
   244         caps += ' _evoext_pullobsmarkers_0'
   230         caps += ' _evoext_obshash_0'
   245         caps += ' _evoext_obshash_0'
       
   246         caps += ' _evoext_b2x_obsmarkers_0'
   231     return caps
   247     return caps
       
   248 
   232 
   249 
   233 # from evolve extension: 10867a8e27c6
   250 # from evolve extension: 10867a8e27c6
   234 # heavily modified
   251 # heavily modified
   235 def extsetup(ui):
   252 def extsetup(ui):
       
   253     localrepo.moderncaps.add('_evoext_b2x_obsmarkers_0')
       
   254     if gboptsmap is not None:
       
   255         gboptsmap['evo_obsmarker'] = 'plain'
       
   256         gboptsmap['evo_obscommon'] = 'plain'
       
   257         gboptsmap['evo_obsheads'] = 'plain'
       
   258     else:
       
   259         gboptslist.append('evo_obsheads')
       
   260         gboptslist.append('evo_obscommon')
       
   261         gboptslist.append('evo_obsmarker')
   236     obsolete.obsstore = pruneobsstore
   262     obsolete.obsstore = pruneobsstore
   237     obsolete.obsstore.relevantmarkers = relevantmarkers
   263     obsolete.obsstore.relevantmarkers = relevantmarkers
   238     hgweb_mod.perms['evoext_pushobsmarkers_0'] = 'push'
   264     hgweb_mod.perms['evoext_pushobsmarkers_0'] = 'push'
   239     hgweb_mod.perms['evoext_pullobsmarkers_0'] = 'pull'
   265     hgweb_mod.perms['evoext_pullobsmarkers_0'] = 'pull'
   240     hgweb_mod.perms['evoext_obshash'] = 'pull'
   266     hgweb_mod.perms['evoext_obshash'] = 'pull'
   241     wireproto.commands['evoext_pushobsmarkers_0'] = (srv_pushobsmarkers, '')
   267     wireproto.commands['evoext_pushobsmarkers_0'] = (srv_pushobsmarkers, '')
   242     wireproto.commands['evoext_pullobsmarkers_0'] = (srv_pullobsmarkers, '*')
   268     wireproto.commands['evoext_pullobsmarkers_0'] = (srv_pullobsmarkers, '*')
   243     # wrap module content
   269     # wrap module content
       
   270     extensions.wrapfunction(exchange, '_getbundleextrapart', _getbundleextrapart)
   244     extensions.wrapfunction(wireproto, 'capabilities', capabilities)
   271     extensions.wrapfunction(wireproto, 'capabilities', capabilities)
   245     # wrap command content
   272     # wrap command content
   246     oldcap, args = wireproto.commands['capabilities']
   273     oldcap, args = wireproto.commands['capabilities']
   247     def newcap(repo, proto):
   274     def newcap(repo, proto):
   248         return capabilities(oldcap, repo, proto)
   275         return capabilities(oldcap, repo, proto)
   249     wireproto.commands['capabilities'] = (newcap, args)
   276     wireproto.commands['capabilities'] = (newcap, args)
   250     wireproto.commands['evoext_obshash'] = (srv_obshash, 'nodes')
   277     wireproto.commands['evoext_obshash'] = (srv_obshash, 'nodes')
   251     # specific simple4server content
   278     # specific simple4server content
   252     extensions.wrapfunction(pushkey, '_nslist', _nslist)
   279     extensions.wrapfunction(pushkey, '_nslist', _nslist)
   253     pushkey._namespaces['namespaces'] = (lambda *x: False, pushkey._nslist)
   280     pushkey._namespaces['namespaces'] = (lambda *x: False, pushkey._nslist)
       
   281 
       
   282 
       
   283 #from evolve extension
       
   284 @bundle2.parthandler('evolve:b2x:obsmarkerv1')
       
   285 def handleobsmarkerv1(op, inpart):
       
   286     """add a stream of obsmarker to the repo"""
       
   287     tr = op.gettransaction()
       
   288     advparams = dict(inpart.advisoryparams)
       
   289     length = advparams.get('totalbytes')
       
   290     if length is None:
       
   291         obsdata = inpart.read()
       
   292     else:
       
   293         length = int(length)
       
   294         data = StringIO()
       
   295         current = 0
       
   296         op.ui.progress('OBSEXC', current, unit="bytes", total=length)
       
   297         while current < length:
       
   298             readsize = min(length-current, 4096)
       
   299             data.write(inpart.read(readsize))
       
   300             current += readsize
       
   301             op.ui.progress('OBSEXC', current, unit="bytes", total=length)
       
   302         op.ui.progress('OBSEXC', None)
       
   303         obsdata = data.getvalue()
       
   304     totalsize = len(obsdata)
       
   305     old = len(op.repo.obsstore._all)
       
   306     op.repo.obsstore.mergemarkers(tr, obsdata)
       
   307     new = len(op.repo.obsstore._all) - old
       
   308     op.records.add('evo_obsmarkers', {'new': new, 'bytes': totalsize})
       
   309     tr.hookargs['evolve_new_obsmarkers'] = str(new)
       
   310 
       
   311 #from evolve extension
       
   312 def _getbundleextrapart(orig, bundler, repo, source, **kwargs):
       
   313     if int(kwargs.pop('evo_obsmarker', False)):
       
   314         common = kwargs.pop('evo_obscommon')
       
   315         common = wireproto.decodelist(common)
       
   316         heads = kwargs.pop('evo_obsheads')
       
   317         heads = wireproto.decodelist(heads)
       
   318         obsdata = _getobsmarkersstream(repo, common=common, heads=heads)
       
   319         if len(obsdata.getvalue()) > 5:
       
   320             advparams = [('totalbytes', str(len(obsdata.getvalue())))]
       
   321             obspart = bundle2.bundlepart('EVOLVE:B2X:OBSMARKERV1',
       
   322                                          advisoryparams=advparams,
       
   323                                          data=obsdata)
       
   324             bundler.addpart(obspart)
       
   325     orig(bundler, repo, source)