hgext3rd/evolve/obsdiscovery.py
changeset 3669 0407965ae79e
parent 3524 6d4095e6bdd3
child 3681 3f90e6c5d140
equal deleted inserted replaced
3668:a6bac0492eff 3669:0407965ae79e
    52     obscache,
    52     obscache,
    53     utility,
    53     utility,
    54     stablerange,
    54     stablerange,
    55     stablerangecache,
    55     stablerangecache,
    56 )
    56 )
       
    57 
       
    58 try: # < hg-4.6
       
    59     from mercurial.wireproto import wirepeer, encodelist, decodelist
       
    60 except ImportError:
       
    61     from mercurial.wireprotov1peer import wirepeer
       
    62     from mercurial.wireprototypes import encodelist, decodelist
    57 
    63 
    58 # prior to hg-4.2 there are not util.timer
    64 # prior to hg-4.2 there are not util.timer
    59 if util.safehasattr(util, 'timer'):
    65 if util.safehasattr(util, 'timer'):
    60     timer = util.timer
    66     timer = util.timer
    61 elif util.safehasattr(time, "perf_counter"):
    67 elif util.safehasattr(time, "perf_counter"):
   666     assert _indexsize < len(data), len(data)
   672     assert _indexsize < len(data), len(data)
   667     headnode = data[:-_indexsize]
   673     headnode = data[:-_indexsize]
   668     index = _unpack(_indexformat, data[-_indexsize:])[0]
   674     index = _unpack(_indexformat, data[-_indexsize:])[0]
   669     return (headnode, index)
   675     return (headnode, index)
   670 
   676 
   671 @eh.addattr(wireproto.wirepeer, 'evoext_obshashrange_v1')
   677 @eh.addattr(wirepeer, 'evoext_obshashrange_v1')
   672 def peer_obshashrange_v0(self, ranges):
   678 def peer_obshashrange_v0(self, ranges):
   673     binranges = [_encrange(r) for r in ranges]
   679     binranges = [_encrange(r) for r in ranges]
   674     encranges = wireproto.encodelist(binranges)
   680     encranges = encodelist(binranges)
   675     d = self._call("evoext_obshashrange_v1", ranges=encranges)
   681     d = self._call("evoext_obshashrange_v1", ranges=encranges)
   676     try:
   682     try:
   677         return wireproto.decodelist(d)
   683         return decodelist(d)
   678     except ValueError:
   684     except ValueError:
   679         self._abort(error.ResponseError(_("unexpected response:"), d))
   685         self._abort(error.ResponseError(_("unexpected response:"), d))
   680 
   686 
   681 @compat.wireprotocommand(eh, 'evoext_obshashrange_v1', 'ranges')
   687 @compat.wireprotocommand(eh, 'evoext_obshashrange_v1', 'ranges')
   682 def srv_obshashrange_v1(repo, proto, ranges):
   688 def srv_obshashrange_v1(repo, proto, ranges):
   683     ranges = wireproto.decodelist(ranges)
   689     ranges = decodelist(ranges)
   684     ranges = [_decrange(r) for r in ranges]
   690     ranges = [_decrange(r) for r in ranges]
   685     hashes = _obshashrange_v0(repo, ranges)
   691     hashes = _obshashrange_v0(repo, ranges)
   686     return wireproto.encodelist(hashes)
   692     return encodelist(hashes)
   687 
   693 
   688 def _useobshashrange(repo):
   694 def _useobshashrange(repo):
   689     base = repo.ui.configbool('experimental', 'obshashrange', False)
   695     base = repo.ui.configbool('experimental', 'obshashrange', False)
   690     if base:
   696     if base:
   691         maxrevs = repo.ui.configint('experimental', 'obshashrange.max-revs', None)
   697         maxrevs = repo.ui.configint('experimental', 'obshashrange.max-revs', None)
   825 
   831 
   826 @eh.addattr(localrepo.localpeer, 'evoext_obshash1')
   832 @eh.addattr(localrepo.localpeer, 'evoext_obshash1')
   827 def local_obshash1(peer, nodes):
   833 def local_obshash1(peer, nodes):
   828     return _obshash(peer._repo, nodes, version=1)
   834     return _obshash(peer._repo, nodes, version=1)
   829 
   835 
   830 @eh.addattr(wireproto.wirepeer, 'evoext_obshash')
   836 @eh.addattr(wirepeer, 'evoext_obshash')
   831 def peer_obshash(self, nodes):
   837 def peer_obshash(self, nodes):
   832     d = self._call("evoext_obshash", nodes=wireproto.encodelist(nodes))
   838     d = self._call("evoext_obshash", nodes=encodelist(nodes))
   833     try:
   839     try:
   834         return wireproto.decodelist(d)
   840         return decodelist(d)
   835     except ValueError:
   841     except ValueError:
   836         self._abort(error.ResponseError(_("unexpected response:"), d))
   842         self._abort(error.ResponseError(_("unexpected response:"), d))
   837 
   843 
   838 @eh.addattr(wireproto.wirepeer, 'evoext_obshash1')
   844 @eh.addattr(wirepeer, 'evoext_obshash1')
   839 def peer_obshash1(self, nodes):
   845 def peer_obshash1(self, nodes):
   840     d = self._call("evoext_obshash1", nodes=wireproto.encodelist(nodes))
   846     d = self._call("evoext_obshash1", nodes=encodelist(nodes))
   841     try:
   847     try:
   842         return wireproto.decodelist(d)
   848         return decodelist(d)
   843     except ValueError:
   849     except ValueError:
   844         self._abort(error.ResponseError(_("unexpected response:"), d))
   850         self._abort(error.ResponseError(_("unexpected response:"), d))
   845 
   851 
   846 @compat.wireprotocommand(eh, 'evoext_obshash', 'nodes')
   852 @compat.wireprotocommand(eh, 'evoext_obshash', 'nodes')
   847 def srv_obshash(repo, proto, nodes):
   853 def srv_obshash(repo, proto, nodes):
   848     return wireproto.encodelist(_obshash(repo, wireproto.decodelist(nodes)))
   854     return encodelist(_obshash(repo, decodelist(nodes)))
   849 
   855 
   850 @compat.wireprotocommand(eh, 'evoext_obshash1', 'nodes')
   856 @compat.wireprotocommand(eh, 'evoext_obshash1', 'nodes')
   851 def srv_obshash1(repo, proto, nodes):
   857 def srv_obshash1(repo, proto, nodes):
   852     return wireproto.encodelist(_obshash(repo, wireproto.decodelist(nodes),
   858     return encodelist(_obshash(repo, decodelist(nodes),
   853                                 version=1))
   859                       version=1))
   854 
   860 
   855 def _obshash_capabilities(orig, repo, proto):
   861 def _obshash_capabilities(orig, repo, proto):
   856     """wrapper to advertise new capability"""
   862     """wrapper to advertise new capability"""
   857     caps = orig(repo, proto)
   863     caps = orig(repo, proto)
   858     if (obsolete.isenabled(repo, obsolete.exchangeopt)
   864     if (obsolete.isenabled(repo, obsolete.exchangeopt)