evolve: handle wireproto module deletion for registering new commands
authorPierre-Yves David <pierre-yves.david@octobus.net>
Thu, 19 Apr 2018 10:55:57 +0200
changeset 3680 e2a91d4d207d
parent 3679 b12c5d107187
child 3681 3f90e6c5d140
evolve: handle wireproto module deletion for registering new commands Module have been deleted in b4d85bc122bd. We can no longer import it blindly.
hgext3rd/evolve/compat.py
--- a/hgext3rd/evolve/compat.py	Thu Apr 19 10:53:59 2018 +0200
+++ b/hgext3rd/evolve/compat.py	Thu Apr 19 10:55:57 2018 +0200
@@ -18,7 +18,6 @@
     obsolete,
     revset,
     util,
-    wireproto,
 )
 from mercurial.hgweb import hgweb_mod
 
@@ -284,17 +283,23 @@
     parsedate = mercurial.util.parsedate
 
 def wireprotocommand(exthelper, name, args='', permission='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)
 
-    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
+    # <= 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: