--- 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"