compat: drop 4.5 related compatibility around wireprotocol module
authorPierre-Yves David <pierre-yves.david@octobus.net>
Tue, 10 Mar 2020 11:07:06 +0100
changeset 5180 515d425c0a05
parent 5179 7c41a1ebcf7f
child 5181 c979d64a2589
compat: drop 4.5 related compatibility around wireprotocol module
hgext3rd/evolve/compat.py
hgext3rd/evolve/obsdiscovery.py
hgext3rd/evolve/obsexchange.py
hgext3rd/serverminitopic.py
hgext3rd/topic/discovery.py
hgext3rd/topic/server.py
--- a/hgext3rd/evolve/compat.py	Tue Mar 10 11:06:37 2020 +0100
+++ b/hgext3rd/evolve/compat.py	Tue Mar 10 11:07:06 2020 +0100
@@ -22,7 +22,6 @@
     util,
     ui as uimod,
 )
-from mercurial.hgweb import hgweb_mod
 
 if pycompat.ispy3:
     arraytobytes = array.array.tobytes
@@ -126,34 +125,9 @@
 
     return mdiff.unidiff(*args)
 
-def wireprotocommand(exthelper, name, args=b'', permission=b'pull'):
-    try:
-        # Since b4d85bc1
-        from mercurial.wireprotov1server import wireprotocommand
-        return wireprotocommand(name, args, permission=permission)
-    except (ImportError, AttributeError):
-        from mercurial import wireproto
-
-    if 3 <= len(wireproto.wireprotocommand.func_defaults):
-        return wireproto.wireprotocommand(name, args, permission=permission)
-
-    # <= hg-4.5 permission must be registered in dictionnary
-    def decorator(func):
-        @eh.extsetup
-        def install(ui):
-            hgweb_mod.perms[name] = permission
-            wireproto.commands[name] = (func, args)
-    return decorator
-
-# mercurial <= 4.5 do not have the updateresult object
-try:
-    from mercurial.merge import updateresult
-except (ImportError, AttributeError):
-    updateresult = None
-
 # 46c2b19a1263f18a5829a21b7a5053019b0c5a31 in hg moved repair.stripbmrevset to
 # scmutil.bookmarkrevs
-# This change is a part of 4.7 cycle, so drop this when we drop support for 4.6
+# This change is a part of 4.7 cycle, so drop this when we drop support for hg <= 4.6
 try:
     bmrevset = repair.stripbmrevset  # pytype: disable=module-attr
 except AttributeError:
--- a/hgext3rd/evolve/obsdiscovery.py	Tue Mar 10 11:06:37 2020 +0100
+++ b/hgext3rd/evolve/obsdiscovery.py	Tue Mar 10 11:07:06 2020 +0100
@@ -45,14 +45,9 @@
     stablerangecache,
 )
 
-try:
-    from mercurial import wireprototypes, wireprotov1server
-    from mercurial.wireprotov1peer import wirepeer
-    from mercurial.wireprototypes import encodelist, decodelist
-except (ImportError, AttributeError): # <= hg-4.5
-    from mercurial import wireproto as wireprototypes
-    wireprotov1server = wireprototypes
-    from mercurial.wireproto import wirepeer, encodelist, decodelist
+from mercurial import wireprototypes, wireprotov1server
+from mercurial.wireprotov1peer import wirepeer
+from mercurial.wireprototypes import encodelist, decodelist
 
 _pack = struct.pack
 _unpack = struct.unpack
@@ -698,7 +693,7 @@
     except ValueError:
         self._abort(error.ResponseError(_(b"unexpected response:"), d))
 
-@compat.wireprotocommand(eh, b'evoext_obshashrange_v1', b'ranges')
+@wireprotov1server.wireprotocommand(b'evoext_obshashrange_v1', b'ranges', b'pull')
 def srv_obshashrange_v1(repo, proto, ranges):
     ranges = decodelist(ranges)
     ranges = [_decrange(r) for r in ranges]
@@ -722,21 +717,10 @@
     caps = orig(repo, proto)
     enabled = _useobshashrange(repo)
     if obsolete.isenabled(repo, obsolete.exchangeopt) and enabled:
-
-        # Compat hg 4.6+ (2f7290555c96)
-        bytesresponse = False
-        if util.safehasattr(caps, 'data'):
-            bytesresponse = True
-            caps = caps.data
-
-        caps = caps.split()
+        caps = caps.data.split()
         caps.append(b'_evoext_obshashrange_v1')
         caps.sort()
-        caps = b' '.join(caps)
-
-        # Compat hg 4.6+ (2f7290555c96)
-        if bytesresponse:
-            caps = wireprototypes.bytesresponse(caps)
+        caps = wireprototypes.bytesresponse(b' '.join(caps))
     return caps
 
 @eh.extsetup
--- a/hgext3rd/evolve/obsexchange.py	Tue Mar 10 11:06:37 2020 +0100
+++ b/hgext3rd/evolve/obsexchange.py	Tue Mar 10 11:07:06 2020 +0100
@@ -16,6 +16,8 @@
     obsolete,
     pushkey,
     util,
+    wireprototypes,
+    wireprotov1server
 )
 
 from mercurial.hgweb import common as hgwebcommon
@@ -44,13 +46,7 @@
 
 @eh.uisetup
 def addgetbundleargs(self):
-    try:
-        from mercurial import wireprototypes
-        gboptsmap = wireprototypes.GETBUNDLE_ARGUMENTS
-    except (ImportError, AttributeError):
-        # <= hg 4.5
-        from mercurial import wireproto
-        gboptsmap = wireproto.gboptsmap
+    gboptsmap = wireprototypes.GETBUNDLE_ARGUMENTS
     gboptsmap[b'evo_obscommon'] = b'nodes'
     gboptsmap[b'evo_missing_nodes'] = b'nodes'
 
@@ -103,34 +99,15 @@
     """wrapper to advertise new capability"""
     caps = orig(repo, proto)
     if obsolete.isenabled(repo, obsolete.exchangeopt):
-
-        # Compat hg 4.6+ (2f7290555c96)
-        bytesresponse = False
-        if util.safehasattr(caps, 'data'):
-            bytesresponse = True
-            caps = caps.data
-
-        caps = caps.split()
+        caps = caps.data.split()
         caps.append(b'_evoext_getbundle_obscommon')
         caps.sort()
-        caps = b' '.join(caps)
-
-        # Compat hg 4.6+ (2f7290555c96)
-        if bytesresponse:
-            from mercurial import wireprototypes
-            caps = wireprototypes.bytesresponse(caps)
+        caps = wireprototypes.bytesresponse(b' '.join(caps))
     return caps
 
 @eh.extsetup
 def extsetup_obscommon(ui):
-    try:
-        from mercurial import wireprototypes, wireprotov1server
-        gboptsmap = wireprototypes.GETBUNDLE_ARGUMENTS
-    except (ImportError, AttributeError):
-        # <= hg 4.5
-        from mercurial import wireproto
-        gboptsmap = wireproto.gboptsmap
-        wireprotov1server = wireproto
+    gboptsmap = wireprototypes.GETBUNDLE_ARGUMENTS
     gboptsmap[b'evo_obscommon'] = b'nodes'
 
     # wrap module content
--- a/hgext3rd/serverminitopic.py	Tue Mar 10 11:06:37 2020 +0100
+++ b/hgext3rd/serverminitopic.py	Tue Mar 10 11:07:06 2020 +0100
@@ -23,12 +23,7 @@
     util,
 )
 
-# hg <= 4.5 (b4d85bc122bd)
-try:
-    from mercurial import wireproto  # pytype: disable=import-error
-    wireproto.branchmap
-except ImportError:
-    from mercurial import wireprotov1server as wireproto
+from mercurial import wireprotov1server
 
 if util.safehasattr(registrar, 'configitem'):
 
@@ -243,5 +238,5 @@
         # Mercurial 4.9; branchcache.fromfile now takes care of this
         # which is alredy defined on _topiccache
         pass
-    extensions.wrapfunction(wireproto, '_capabilities', wireprotocaps)
+    extensions.wrapfunction(wireprotov1server, '_capabilities', wireprotocaps)
     extensions.wrapfunction(context.changectx, 'branch', topicbranch)
--- a/hgext3rd/topic/discovery.py	Tue Mar 10 11:06:37 2020 +0100
+++ b/hgext3rd/topic/discovery.py	Tue Mar 10 11:07:06 2020 +0100
@@ -17,12 +17,7 @@
     compat,
 )
 
-# hg <= 4.5 (b4d85bc122bd)
-try:
-    from mercurial import wireproto  # pytype: disable=import-error
-    wireproto.branchmap
-except (AttributeError, ImportError):
-    from mercurial import wireprotov1server as wireproto
+from mercurial import wireprotov1server
 
 def _headssummary(orig, pushop, *args, **kwargs):
     # In mercurial > 4.3, we receive the pushop as arguments
@@ -207,8 +202,8 @@
 def modsetup(ui):
     """run at uisetup time to install all destinations wrapping"""
     extensions.wrapfunction(discovery, '_headssummary', _headssummary)
-    extensions.wrapfunction(wireproto, 'branchmap', wireprotobranchmap)
-    extensions.wrapfunction(wireproto, '_capabilities', wireprotocaps)
+    extensions.wrapfunction(wireprotov1server, 'branchmap', wireprotobranchmap)
+    extensions.wrapfunction(wireprotov1server, '_capabilities', wireprotocaps)
     # we need a proper wrap b2 part stuff
     extensions.wrapfunction(bundle2, 'handlecheckheads', handlecheckheads)
     bundle2.handlecheckheads.params = frozenset()
--- a/hgext3rd/topic/server.py	Tue Mar 10 11:06:37 2020 +0100
+++ b/hgext3rd/topic/server.py	Tue Mar 10 11:07:06 2020 +0100
@@ -10,7 +10,6 @@
     wireprotov1server,
 )
 
-
 try:
     from mercurial.utils import (
         repoviewutil,
@@ -54,14 +53,6 @@
         filteredrevs = frozenset(filteredrevs | extrafiltered)
     return filteredrevs
 
-def wireprotocommand(name, args=b'', permission=b'pull'):
-    try:
-        from mercurial.wireprotov1server import wireprotocommand
-    except (ImportError, AttributeError):
-        # hg <= 4.6 (b4d85bc122bd)
-        from mercurial.wireproto import wireprotocommand
-    return wireprotocommand(name, args, permission=permission)
-
 def wrapheads(orig, repo, proto):
     """wrap head to hide topic^W draft changeset to old client"""
     hidetopics = repo.ui.configbool(b'experimental', b'topic.server-gate-topic-changesets')
@@ -85,8 +76,8 @@
 def setupserver(ui):
     extensions.wrapfunction(wireprotov1server, 'heads', wrapheads)
     wireprotov1server.commands.pop(b'heads')
-    wireprotocommand(b'heads', permission=b'pull')(wireprotov1server.heads)
-    wireprotocommand(b'_exttopics_heads', permission=b'pull')(topicheads)
+    wireprotov1server.wireprotocommand(b'heads', permission=b'pull')(wireprotov1server.heads)
+    wireprotov1server.wireprotocommand(b'_exttopics_heads', permission=b'pull')(topicheads)
     extensions.wrapfunction(wireprotov1server, '_capabilities', wireprotocaps)
 
     class topicpeerexecutor(wireprotov1peer.peerexecutor):