changeset 35:70730f6d01a8

Use registrar.command when available (hg 4.3)
author mr
date Tue, 06 Mar 2018 09:19:20 -0800
parents 15882341bf0f
children aed87627cf7b
files trees.py
diffstat 1 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/trees.py	Tue Mar 06 09:19:19 2018 -0800
+++ b/trees.py	Tue Mar 06 09:19:20 2018 -0800
@@ -142,7 +142,8 @@
 
 # From Mercurial 1.9, the preferred way to define commands is using the @command
 # decorator. From version 3.8, the old way of directly defining the command table
-# was deprecated and in 4.1 it's no longer supported at all.
+# was deprecated and in 4.1 it's no longer supported at all. From version 4.3,
+# registrar.command is preferred over cmdutil.command.
 #
 # By defining a wrapper function, compatibility with most versions is kept. The
 # wrapper first tries to call the actual decorator if it is defined. If it isn't
@@ -154,15 +155,20 @@
 # further down in extsetup.
 cmdtable = {}
 cmdutil_command = None
-if hasattr(cmdutil, 'command'):
-    cmdutil_command = cmdutil.command(cmdtable)
+try:
+    from mercurial import registrar
+    cmdutil_command = registrar.command(cmdtable)
+except:
+    from mercurial import cmdutil
+    if hasattr(cmdutil, 'command'):
+        cmdutil_command = cmdutil.command(cmdtable)
 
 def command(name, options=(), synopsis=None, norepo=False, optionalrepo=False):
     if cmdutil_command:
         try:
             return cmdutil_command(name, options, synopsis, norepo, optionalrepo)
         except:
-            # Mercurial versions older than 3.1 does not support all the options
+            # Mercurial versions older than 3.1 do not support all the options
             # used here. If it fails, fall back to workaround.
             pass
     def decorator(func):