deprecation: fix cmdutil.command deprecation warning stable
authorBoris Feld <boris.feld@octobus.net>
Mon, 22 May 2017 14:57:47 +0200
branchstable
changeset 2464 2b53a2a21bbb
parent 2462 560175d6a83e
child 2465 479646a3873a
deprecation: fix cmdutil.command deprecation warning
hgext3rd/evolve/exthelper.py
hgext3rd/evolve/hack/directaccess.py
hgext3rd/evolve/hack/drophack.py
hgext3rd/evolve/hack/inhibit.py
hgext3rd/evolve/legacy.py
hgext3rd/topic/__init__.py
--- a/hgext3rd/evolve/exthelper.py	Sun May 21 23:56:33 2017 +0200
+++ b/hgext3rd/evolve/exthelper.py	Mon May 22 14:57:47 2017 +0200
@@ -3,13 +3,20 @@
 #####################################################################
 
 from mercurial import (
-    cmdutil,
     commands,
     extensions,
+    registrar,
     revset,
     templatekw,
+    util,
 )
 
+if util.safehasattr(registrar, 'command'):
+    command = registrar.command
+else: # compat with hg < 4.3
+    from mercurial import cmdutil
+    command = cmdutil.command
+
 class exthelper(object):
     """Helper for modular extension setup
 
@@ -30,7 +37,7 @@
         self._functionwrappers = []
         self._duckpunchers = []
         self.cmdtable = {}
-        self.command = cmdutil.command(self.cmdtable)
+        self.command = command(self.cmdtable)
 
     def merge(self, other):
         self._uicallables.extend(other._uicallables)
--- a/hgext3rd/evolve/hack/directaccess.py	Sun May 21 23:56:33 2017 +0200
+++ b/hgext3rd/evolve/hack/directaccess.py	Mon May 22 14:57:47 2017 +0200
@@ -6,9 +6,9 @@
 to xxx.
 """
 from mercurial import extensions
-from mercurial import cmdutil
 from mercurial import repoview
 from mercurial import branchmap
+from mercurial import registrar
 from mercurial import revset
 from mercurial import error
 from mercurial import commands
@@ -17,7 +17,12 @@
 from mercurial.i18n import _
 
 cmdtable = {}
-command = cmdutil.command(cmdtable)
+
+if util.safehasattr(registrar, 'command'):
+    command = registrar.command(cmdtable)
+else: # compat with hg < 4.3
+    from mercurial import cmdutil
+    command = cmdutil.command(cmdtable)
 
 # By default, all the commands have directaccess with warnings
 # List of commands that have no directaccess and directaccess with no warning
--- a/hgext3rd/evolve/hack/drophack.py	Sun May 21 23:56:33 2017 +0200
+++ b/hgext3rd/evolve/hack/drophack.py	Mon May 22 14:57:47 2017 +0200
@@ -12,7 +12,7 @@
 import contextlib
 
 from mercurial.i18n import _
-from mercurial import cmdutil
+from mercurial import registrar
 from mercurial import repair
 from mercurial import scmutil
 from mercurial import lock as lockmod
@@ -20,7 +20,12 @@
 from mercurial import commands
 
 cmdtable = {}
-command = cmdutil.command(cmdtable)
+
+if util.safehasattr(registrar, 'command'):
+    command = registrar.command(cmdtable)
+else: # compat with hg < 4.3
+    from mercurial import cmdutil
+    command = cmdutil.command(cmdtable)
 
 
 @contextlib.contextmanager
--- a/hgext3rd/evolve/hack/inhibit.py	Sun May 21 23:56:33 2017 +0200
+++ b/hgext3rd/evolve/hack/inhibit.py	Mon May 22 14:57:47 2017 +0200
@@ -14,20 +14,25 @@
 However as the inhibitor are not fitting in an append only model, this is
 incompatible with sharing mutable history.
 """
-from mercurial import localrepo
-from mercurial import obsolete
-from mercurial import extensions
-from mercurial import cmdutil
+from mercurial import bookmarks
+from mercurial import commands
 from mercurial import error
+from mercurial import extensions
+from mercurial import localrepo
+from mercurial import lock as lockmod
+from mercurial import obsolete
+from mercurial import registrar
 from mercurial import scmutil
-from mercurial import commands
-from mercurial import lock as lockmod
-from mercurial import bookmarks
 from mercurial import util
 from mercurial.i18n import _
 
 cmdtable = {}
-command = cmdutil.command(cmdtable)
+
+if util.safehasattr(registrar, 'command'):
+    command = registrar.command(cmdtable)
+else: # compat with hg < 4.3
+    from mercurial import cmdutil
+    command = cmdutil.command(cmdtable)
 
 def _inhibitenabled(repo):
     return util.safehasattr(repo, '_obsinhibit')
--- a/hgext3rd/evolve/legacy.py	Sun May 21 23:56:33 2017 +0200
+++ b/hgext3rd/evolve/legacy.py	Mon May 22 14:57:47 2017 +0200
@@ -24,12 +24,17 @@
 import sys
 import json
 
-from mercurial import cmdutil
 from mercurial.i18n import _
 from mercurial import lock as lockmod
 from mercurial.node import bin, nullid
+from mercurial import registrar
 from mercurial import util
 
+if util.safehasattr(registrar, 'command'):
+    commandfunc = registrar.command
+else: # compat with hg < 4.3
+    from mercurial import cmdutil
+    commandfunc = cmdutil.command
 
 #####################################################################
 ### Older format management                                       ###
@@ -75,7 +80,7 @@
     return rels
 
 cmdtable = {}
-command = cmdutil.command(cmdtable)
+command = commandfunc(cmdtable)
 @command('debugconvertobsolete', [], '')
 def cmddebugconvertobsolete(ui, repo):
     """import markers from an .hg/obsolete-relations file"""
--- a/hgext3rd/topic/__init__.py	Sun May 21 23:56:33 2017 +0200
+++ b/hgext3rd/topic/__init__.py	Mon May 22 14:57:47 2017 +0200
@@ -69,6 +69,7 @@
     obsolete,
     patch,
     phases,
+    registrar,
     util,
 )
 
@@ -81,8 +82,13 @@
     discovery,
 )
 
+if util.safehasattr(registrar, 'command'):
+    commandfunc = registrar.command
+else: # compat with hg < 4.3
+    commandfunc = cmdutil.command
+
 cmdtable = {}
-command = cmdutil.command(cmdtable)
+command = commandfunc(cmdtable)
 colortable = {'topic.active': 'green',
               'topic.list.troubledcount': 'red',
               'topic.list.headcount.multiple': 'yellow',