Mercurial > evolve
changeset 3669:0407965ae79e
compat: deal with change in the wireproto module
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 17 Apr 2018 15:04:15 +0200 |
parents | a6bac0492eff |
children | 1043e9c54355 |
files | hgext3rd/evolve/obsdiscovery.py hgext3rd/evolve/obsexchange.py |
diffstat | 2 files changed, 33 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext3rd/evolve/obsdiscovery.py Mon Apr 16 12:46:23 2018 -0700 +++ b/hgext3rd/evolve/obsdiscovery.py Tue Apr 17 15:04:15 2018 +0200 @@ -55,6 +55,12 @@ stablerangecache, ) +try: # < hg-4.6 + from mercurial.wireproto import wirepeer, encodelist, decodelist +except ImportError: + from mercurial.wireprotov1peer import wirepeer + from mercurial.wireprototypes import encodelist, decodelist + # prior to hg-4.2 there are not util.timer if util.safehasattr(util, 'timer'): timer = util.timer @@ -668,22 +674,22 @@ index = _unpack(_indexformat, data[-_indexsize:])[0] return (headnode, index) -@eh.addattr(wireproto.wirepeer, 'evoext_obshashrange_v1') +@eh.addattr(wirepeer, 'evoext_obshashrange_v1') def peer_obshashrange_v0(self, ranges): binranges = [_encrange(r) for r in ranges] - encranges = wireproto.encodelist(binranges) + encranges = encodelist(binranges) d = self._call("evoext_obshashrange_v1", ranges=encranges) try: - return wireproto.decodelist(d) + return decodelist(d) except ValueError: self._abort(error.ResponseError(_("unexpected response:"), d)) @compat.wireprotocommand(eh, 'evoext_obshashrange_v1', 'ranges') def srv_obshashrange_v1(repo, proto, ranges): - ranges = wireproto.decodelist(ranges) + ranges = decodelist(ranges) ranges = [_decrange(r) for r in ranges] hashes = _obshashrange_v0(repo, ranges) - return wireproto.encodelist(hashes) + return encodelist(hashes) def _useobshashrange(repo): base = repo.ui.configbool('experimental', 'obshashrange', False) @@ -827,30 +833,30 @@ def local_obshash1(peer, nodes): return _obshash(peer._repo, nodes, version=1) -@eh.addattr(wireproto.wirepeer, 'evoext_obshash') +@eh.addattr(wirepeer, 'evoext_obshash') def peer_obshash(self, nodes): - d = self._call("evoext_obshash", nodes=wireproto.encodelist(nodes)) + d = self._call("evoext_obshash", nodes=encodelist(nodes)) try: - return wireproto.decodelist(d) + return decodelist(d) except ValueError: self._abort(error.ResponseError(_("unexpected response:"), d)) -@eh.addattr(wireproto.wirepeer, 'evoext_obshash1') +@eh.addattr(wirepeer, 'evoext_obshash1') def peer_obshash1(self, nodes): - d = self._call("evoext_obshash1", nodes=wireproto.encodelist(nodes)) + d = self._call("evoext_obshash1", nodes=encodelist(nodes)) try: - return wireproto.decodelist(d) + return decodelist(d) except ValueError: self._abort(error.ResponseError(_("unexpected response:"), d)) @compat.wireprotocommand(eh, 'evoext_obshash', 'nodes') def srv_obshash(repo, proto, nodes): - return wireproto.encodelist(_obshash(repo, wireproto.decodelist(nodes))) + return encodelist(_obshash(repo, decodelist(nodes))) @compat.wireprotocommand(eh, 'evoext_obshash1', 'nodes') def srv_obshash1(repo, proto, nodes): - return wireproto.encodelist(_obshash(repo, wireproto.decodelist(nodes), - version=1)) + return encodelist(_obshash(repo, decodelist(nodes), + version=1)) def _obshash_capabilities(orig, repo, proto): """wrapper to advertise new capability"""
--- a/hgext3rd/evolve/obsexchange.py Mon Apr 16 12:46:23 2018 -0700 +++ b/hgext3rd/evolve/obsexchange.py Tue Apr 17 15:04:15 2018 +0200 @@ -60,8 +60,13 @@ @eh.uisetup def addgetbundleargs(self): - wireproto.gboptsmap['evo_obscommon'] = 'nodes' - wireproto.gboptsmap['evo_missing_nodes'] = 'nodes' + if util.safehasattr(wireproto, 'gboptsmap'): # <= hg 4.5 + gboptsmap = wireproto.gboptsmap + else: + from mercurial import wireprototypes + gboptsmap = wireprototypes.GETBUNDLE_ARGUMENTS + gboptsmap['evo_obscommon'] = 'nodes' + gboptsmap['evo_missing_nodes'] = 'nodes' @eh.wrapfunction(exchange, '_pullbundle2extraprepare') def _addobscommontob2pull(orig, pullop, kwargs): @@ -132,7 +137,12 @@ @eh.extsetup def extsetup_obscommon(ui): - wireproto.gboptsmap['evo_obscommon'] = 'nodes' + if util.safehasattr(wireproto, 'gboptsmap'): # <= hg 4.5 + gboptsmap = wireproto.gboptsmap + else: + from mercurial import wireprototypes + gboptsmap = wireprototypes.GETBUNDLE_ARGUMENTS + gboptsmap['evo_obscommon'] = 'nodes' # wrap module content origfunc = exchange.getbundle2partsmapping['obsmarkers']