Mercurial > evolve
changeset 3682:72f61b9cb8e9
evolve: add support for hg >= b4d85bc1
Mercurial commit b4d85bc1 deleted the wireproto module and its
contents are now in various other modules, so we can not even do
unchecked imports of it now.
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Wed, 18 Apr 2018 22:54:11 -0700 |
parents | 3f90e6c5d140 |
children | 2a62f0f480f3 |
files | hgext3rd/evolve/obsexchange.py |
diffstat | 1 files changed, 31 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext3rd/evolve/obsexchange.py Thu Apr 19 10:59:12 2018 +0200 +++ b/hgext3rd/evolve/obsexchange.py Wed Apr 18 22:54:11 2018 -0700 @@ -24,7 +24,6 @@ obsolete, pushkey, util, - wireproto, ) from mercurial.hgweb import common as hgwebcommon @@ -54,11 +53,13 @@ @eh.uisetup def addgetbundleargs(self): - if util.safehasattr(wireproto, 'gboptsmap'): # <= hg 4.5 - gboptsmap = wireproto.gboptsmap - else: + try: from mercurial import wireprototypes gboptsmap = wireprototypes.GETBUNDLE_ARGUMENTS + except (ImportError, AttributeError): + # <= hg 4.5 + from mercurial import wireproto + gboptsmap = wireproto.gboptsmap gboptsmap['evo_obscommon'] = 'nodes' gboptsmap['evo_missing_nodes'] = 'nodes' @@ -131,11 +132,14 @@ @eh.extsetup def extsetup_obscommon(ui): - if util.safehasattr(wireproto, 'gboptsmap'): # <= hg 4.5 + try: + from mercurial import wireprototypes, wireprotov1server + gboptsmap = wireprototypes.GETBUNDLE_ARGUMENTS + except (ImportError, AttributeError): + # <= hg 4.5 + from mercurial import wireproto gboptsmap = wireproto.gboptsmap - else: - from mercurial import wireprototypes - gboptsmap = wireprototypes.GETBUNDLE_ARGUMENTS + wireprotov1server = wireproto gboptsmap['evo_obscommon'] = 'nodes' # wrap module content @@ -145,13 +149,14 @@ return _getbundleobsmarkerpart(origfunc, *args, **kwargs) exchange.getbundle2partsmapping['obsmarkers'] = newfunc - extensions.wrapfunction(wireproto, 'capabilities', _obscommon_capabilities) + extensions.wrapfunction(wireprotov1server, 'capabilities', + _obscommon_capabilities) # wrap command content - oldcap, args = wireproto.commands['capabilities'] + oldcap, args = wireprotov1server.commands['capabilities'] def newcap(repo, proto): return _obscommon_capabilities(oldcap, repo, proto) - wireproto.commands['capabilities'] = (newcap, args) + wireprotov1server.commands['capabilities'] = (newcap, args) def _pushobsmarkers(repo, data): tr = lock = None @@ -174,7 +179,12 @@ data = fp.getvalue() fp.close() _pushobsmarkers(repo, data) - return wireproto.pushres(0) + try: + from mercurial import wireprototypes + wireprototypes.pushres # force demandimport + except (ImportError, AttributeError): + from mercurial import wireproto as wireprototypes + return wireprototypes.pushres(0) def _getobsmarkersstream(repo, heads=None, common=None): """Get a binary stream for all markers relevant to `::<heads> - ::<common>` @@ -206,17 +216,23 @@ Serves relevant to changeset between heads and common. The stream is prefix by a -string- representation of an integer. This integer is the size of the stream.""" - opts = wireproto.options('', ['heads', 'common'], others) + try: + from mercurial import wireprototypes, wireprotov1server + wireprototypes.pushres # force demandimport + except (ImportError, AttributeError): + from mercurial import wireproto as wireprototypes + wireprotov1server = wireprototypes + opts = wireprotov1server.options('', ['heads', 'common'], others) for k, v in opts.iteritems(): if k in ('heads', 'common'): - opts[k] = wireproto.decodelist(v) + opts[k] = wireprototypes.decodelist(v) obsdata = _getobsmarkersstream(repo, **opts) finaldata = StringIO() obsdata = obsdata.getvalue() finaldata.write('%20i' % len(obsdata)) finaldata.write(obsdata) finaldata.seek(0) - return wireproto.streamres(reader=finaldata, v1compressible=True) + return wireprototypes.streamres(reader=finaldata, v1compressible=True) abortmsg = "won't exchange obsmarkers through pushkey" hint = "upgrade your client or server to use the bundle2 protocol"