hgext/simple4server.py
branchstable
changeset 1146 3de3d85069fd
parent 1097 580a2d838996
child 1215 004e21b8d67b
child 1245 580a8f5ea462
equal deleted inserted replaced
1115:cc19b6400dae 1146:3de3d85069fd
    73     finally:
    73     finally:
    74         lock.release()
    74         lock.release()
    75     repo.hook('evolve_pushobsmarkers')
    75     repo.hook('evolve_pushobsmarkers')
    76     return wireproto.pushres(0)
    76     return wireproto.pushres(0)
    77 
    77 
    78 # from mercurial.obsolete: 19e9478c1a22
       
    79 def _encodemarkersstream(fp, markers):
       
    80     """write a binary version of a set of markers
       
    81 
       
    82     Includes the initial version number"""
       
    83     fp.write(_pack('>B', 0))
       
    84     for mark in markers:
       
    85         fp.write(obsolete._encodeonemarker(mark))
       
    86 
       
    87 # from evolve extension: 1a23c7c52a43
    78 # from evolve extension: 1a23c7c52a43
    88 def _getobsmarkersstream(repo, heads=None, common=None):
    79 def _getobsmarkersstream(repo, heads=None, common=None):
    89     """Get a binary stream for all markers relevant to `::<heads> - ::<common>`
    80     """Get a binary stream for all markers relevant to `::<heads> - ::<common>`
    90     """
    81     """
    91     revset = ''
    82     revset = ''
   102         revset += ' - (::%ln)'
    93         revset += ' - (::%ln)'
   103         args.append(common)
    94         args.append(common)
   104     nodes = [c.node() for c in repo.set(revset, *args)]
    95     nodes = [c.node() for c in repo.set(revset, *args)]
   105     markers = repo.obsstore.relevantmarkers(nodes)
    96     markers = repo.obsstore.relevantmarkers(nodes)
   106     obsdata = StringIO()
    97     obsdata = StringIO()
   107     _encodemarkersstream(obsdata, markers)
    98     for chunk in obsolete.encodemarkers(markers, True):
       
    99         obsdata.write(chunk)
   108     obsdata.seek(0)
   100     obsdata.seek(0)
   109     return obsdata
   101     return obsdata
   110 
   102 
   111 if not util.safehasattr(obsolete.obsstore, 'relevantmarkers'):
   103 if not util.safehasattr(obsolete.obsstore, 'relevantmarkers'):
   112     # from evolve extension: 1a23c7c52a43
   104     # from evolve extension: 1a23c7c52a43
   206             if p != node.nullid:
   198             if p != node.nullid:
   207                 entry += 1
   199                 entry += 1
   208                 sha.update(p)
   200                 sha.update(p)
   209         tmarkers = repo.obsstore.relevantmarkers([ctx.node()])
   201         tmarkers = repo.obsstore.relevantmarkers([ctx.node()])
   210         if tmarkers:
   202         if tmarkers:
   211             bmarkers = [obsolete._encodeonemarker(m) for m in tmarkers]
   203             bmarkers = [obsolete._fm0encodeonemarker(m) for m in tmarkers]
   212             bmarkers.sort()
   204             bmarkers.sort()
   213             for m in bmarkers:
   205             for m in bmarkers:
   214                 entry += 1
   206                 entry += 1
   215                 sha.update(m)
   207                 sha.update(m)
   216         if entry:
   208         if entry:
   224     """hash of binary version of relevant markers + obsparent
   216     """hash of binary version of relevant markers + obsparent
   225 
   217 
   226     (special case so that all empty are hashed as nullid)"""
   218     (special case so that all empty are hashed as nullid)"""
   227     hashs = _obsrelsethashtree(repo)
   219     hashs = _obsrelsethashtree(repo)
   228     nm = repo.changelog.nodemap
   220     nm = repo.changelog.nodemap
   229     return  [hashs[nm.get(n)][1] for n in nodes]
   221     revs = [nm.get(n) for n in nodes]
       
   222     return [r is None and node.nullid or hashs[r][1] for r in revs]
   230 
   223 
   231 # from evolve extension: 1a23c7c52a43
   224 # from evolve extension: 1a23c7c52a43
   232 def srv_obshash(repo, proto, nodes):
   225 def srv_obshash(repo, proto, nodes):
   233     """give the obshash of a a set of node
   226     """give the obshash of a a set of node
   234 
   227 
   242     advertise = repo.ui.configbool('__temporary__', 'advertiseobsolete', True)
   235     advertise = repo.ui.configbool('__temporary__', 'advertiseobsolete', True)
   243     if obsolete._enabled and advertise:
   236     if obsolete._enabled and advertise:
   244         caps += ' _evoext_pushobsmarkers_0'
   237         caps += ' _evoext_pushobsmarkers_0'
   245         caps += ' _evoext_pullobsmarkers_0'
   238         caps += ' _evoext_pullobsmarkers_0'
   246         caps += ' _evoext_obshash_0'
   239         caps += ' _evoext_obshash_0'
   247         caps += ' _evoext_b2x_obsmarkers_0'
   240         caps += ' _evoext_getbundle_obscommon'
   248     return caps
   241     return caps
   249 
   242 
       
   243 def _getbundleobsmarkerpart(orig, bundler, repo, source, heads=None, common=None,
       
   244                             bundlecaps=None, **kwargs):
       
   245     if 'evo_obscommon' not in kwargs:
       
   246         return orig(bundler, repo, source, heads, common, bundlecaps, **kwargs)
       
   247 
       
   248     if kwargs.get('obsmarkers', False):
       
   249         if heads is None:
       
   250             heads = repo.heads()
       
   251         obscommon = kwargs.get('evo_obscommon', ())
       
   252         obsset = repo.set('::%ln - ::%ln', heads, obscommon)
       
   253         subset = [c.node() for c in obsset]
       
   254         markers = repo.obsstore.relevantmarkers(subset)
       
   255         exchange.buildobsmarkerspart(bundler, markers)
   250 
   256 
   251 # from evolve extension: 10867a8e27c6
   257 # from evolve extension: 10867a8e27c6
   252 # heavily modified
   258 # heavily modified
   253 def extsetup(ui):
   259 def extsetup(ui):
   254     localrepo.moderncaps.add('_evoext_b2x_obsmarkers_0')
   260     localrepo.moderncaps.add('_evoext_b2x_obsmarkers_0')
   255     if gboptsmap is not None:
   261     gboptsmap['evo_obscommon'] = 'nodes'
   256         gboptsmap['evo_obsmarker'] = 'plain'
       
   257         gboptsmap['evo_obscommon'] = 'plain'
       
   258         gboptsmap['evo_obsheads'] = 'plain'
       
   259     else:
       
   260         gboptslist.append('evo_obsheads')
       
   261         gboptslist.append('evo_obscommon')
       
   262         gboptslist.append('evo_obsmarker')
       
   263     if not util.safehasattr(obsolete.obsstore, 'relevantmarkers'):
   262     if not util.safehasattr(obsolete.obsstore, 'relevantmarkers'):
   264         obsolete.obsstore = pruneobsstore
   263         obsolete.obsstore = pruneobsstore
   265         obsolete.obsstore.relevantmarkers = relevantmarkers
   264         obsolete.obsstore.relevantmarkers = relevantmarkers
   266     hgweb_mod.perms['evoext_pushobsmarkers_0'] = 'push'
   265     hgweb_mod.perms['evoext_pushobsmarkers_0'] = 'push'
   267     hgweb_mod.perms['evoext_pullobsmarkers_0'] = 'pull'
   266     hgweb_mod.perms['evoext_pullobsmarkers_0'] = 'pull'
   268     hgweb_mod.perms['evoext_obshash'] = 'pull'
   267     hgweb_mod.perms['evoext_obshash'] = 'pull'
   269     wireproto.commands['evoext_pushobsmarkers_0'] = (srv_pushobsmarkers, '')
   268     wireproto.commands['evoext_pushobsmarkers_0'] = (srv_pushobsmarkers, '')
   270     wireproto.commands['evoext_pullobsmarkers_0'] = (srv_pullobsmarkers, '*')
   269     wireproto.commands['evoext_pullobsmarkers_0'] = (srv_pullobsmarkers, '*')
   271     # wrap module content
   270     # wrap module content
   272     extensions.wrapfunction(exchange, '_getbundleextrapart', _getbundleextrapart)
   271     extensions.wrapfunction(exchange, '_pullbundle2extraprepare', _getbundleobsmarkerpart)
   273     extensions.wrapfunction(wireproto, 'capabilities', capabilities)
   272     extensions.wrapfunction(wireproto, 'capabilities', capabilities)
   274     # wrap command content
   273     # wrap command content
   275     oldcap, args = wireproto.commands['capabilities']
   274     oldcap, args = wireproto.commands['capabilities']
   276     def newcap(repo, proto):
   275     def newcap(repo, proto):
   277         return capabilities(oldcap, repo, proto)
   276         return capabilities(oldcap, repo, proto)
   279     wireproto.commands['evoext_obshash'] = (srv_obshash, 'nodes')
   278     wireproto.commands['evoext_obshash'] = (srv_obshash, 'nodes')
   280     # specific simple4server content
   279     # specific simple4server content
   281     extensions.wrapfunction(pushkey, '_nslist', _nslist)
   280     extensions.wrapfunction(pushkey, '_nslist', _nslist)
   282     pushkey._namespaces['namespaces'] = (lambda *x: False, pushkey._nslist)
   281     pushkey._namespaces['namespaces'] = (lambda *x: False, pushkey._nslist)
   283 
   282 
   284 
       
   285 #from evolve extension
       
   286 @bundle2.parthandler('evolve:b2x:obsmarkerv1')
       
   287 def handleobsmarkerv1(op, inpart):
       
   288     """add a stream of obsmarker to the repo"""
       
   289     tr = op.gettransaction()
       
   290     advparams = dict(inpart.advisoryparams)
       
   291     length = advparams.get('totalbytes')
       
   292     if length is None:
       
   293         obsdata = inpart.read()
       
   294     else:
       
   295         length = int(length)
       
   296         data = StringIO()
       
   297         current = 0
       
   298         op.ui.progress('OBSEXC', current, unit="bytes", total=length)
       
   299         while current < length:
       
   300             readsize = min(length-current, 4096)
       
   301             data.write(inpart.read(readsize))
       
   302             current += readsize
       
   303             op.ui.progress('OBSEXC', current, unit="bytes", total=length)
       
   304         op.ui.progress('OBSEXC', None)
       
   305         obsdata = data.getvalue()
       
   306     totalsize = len(obsdata)
       
   307     old = len(op.repo.obsstore._all)
       
   308     op.repo.obsstore.mergemarkers(tr, obsdata)
       
   309     new = len(op.repo.obsstore._all) - old
       
   310     op.records.add('evo_obsmarkers', {'new': new, 'bytes': totalsize})
       
   311     tr.hookargs['evolve_new_obsmarkers'] = str(new)
       
   312 
       
   313 #from evolve extension
       
   314 def _getbundleextrapart(orig, bundler, repo, source, **kwargs):
       
   315     if int(kwargs.pop('evo_obsmarker', False)):
       
   316         common = kwargs.pop('evo_obscommon')
       
   317         common = wireproto.decodelist(common)
       
   318         heads = kwargs.pop('evo_obsheads')
       
   319         heads = wireproto.decodelist(heads)
       
   320         obsdata = _getobsmarkersstream(repo, common=common, heads=heads)
       
   321         if len(obsdata.getvalue()) > 5:
       
   322             advparams = [('totalbytes', str(len(obsdata.getvalue())))]
       
   323             obspart = bundle2.bundlepart('EVOLVE:B2X:OBSMARKERV1',
       
   324                                          advisoryparams=advparams,
       
   325                                          data=obsdata)
       
   326             bundler.addpart(obspart)
       
   327     orig(bundler, repo, source)