obsdiscovery: add compatibility layer to register wireproto command
authorPierre-Yves David <pierre-yves.david@octobus.net>
Wed, 14 Mar 2018 02:08:53 +0100
changeset 3524 6d4095e6bdd3
parent 3523 63bba357a1b4
child 3525 300d7d019b98
obsdiscovery: add compatibility layer to register wireproto command Mercurial core 0b18604db95e changed the way permissions are registered.
hgext3rd/evolve/compat.py
hgext3rd/evolve/obsdiscovery.py
--- a/hgext3rd/evolve/compat.py	Wed Mar 14 02:21:07 2018 +0100
+++ b/hgext3rd/evolve/compat.py	Wed Mar 14 02:08:53 2018 +0100
@@ -16,7 +16,9 @@
     obsolete,
     revset,
     util,
+    wireproto,
 )
+from mercurial.hgweb import hgweb_mod
 
 # hg < 4.2 compat
 try:
@@ -265,3 +267,16 @@
     import mercurial.util
     makedate = mercurial.util.makedate
     parsedate = mercurial.util.parsedate
+
+def wireprotocommand(exthelper, name, args='', permission='pull'):
+    if 3 <= len(wireproto.wireprotocommand.func_defaults):
+        return wireproto.wireprotocommand(name, args, permission=permission)
+
+    else:
+        # <= 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
--- a/hgext3rd/evolve/obsdiscovery.py	Wed Mar 14 02:21:07 2018 +0100
+++ b/hgext3rd/evolve/obsdiscovery.py	Wed Mar 14 02:08:53 2018 +0100
@@ -44,10 +44,10 @@
     util,
     wireproto,
 )
-from mercurial.hgweb import hgweb_mod
 from mercurial.i18n import _
 
 from . import (
+    compat,
     exthelper,
     obscache,
     utility,
@@ -678,6 +678,7 @@
     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 = [_decrange(r) for r in ranges]
@@ -721,9 +722,6 @@
 
 @eh.extsetup
 def obshashrange_extsetup(ui):
-    hgweb_mod.perms['evoext_obshashrange_v1'] = 'pull'
-
-    wireproto.commands['evoext_obshashrange_v1'] = (srv_obshashrange_v1, 'ranges')
     ###
     extensions.wrapfunction(wireproto, 'capabilities', _obshashrange_capabilities)
     # wrap command content
@@ -845,9 +843,11 @@
     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)))
 
+@compat.wireprotocommand(eh, 'evoext_obshash1', 'nodes')
 def srv_obshash1(repo, proto, nodes):
     return wireproto.encodelist(_obshash(repo, wireproto.decodelist(nodes),
                                 version=1))
@@ -878,11 +878,6 @@
 
 @eh.extsetup
 def obshash_extsetup(ui):
-    hgweb_mod.perms['evoext_obshash'] = 'pull'
-    hgweb_mod.perms['evoext_obshash1'] = 'pull'
-
-    wireproto.commands['evoext_obshash'] = (srv_obshash, 'nodes')
-    wireproto.commands['evoext_obshash1'] = (srv_obshash1, 'nodes')
     extensions.wrapfunction(wireproto, 'capabilities', _obshash_capabilities)
     # wrap command content
     oldcap, args = wireproto.commands['capabilities']