Patchwork [1,of,2,deprecations] dispatch: stop supporting non-use of @command

login
register
mail settings
Submitter Augie Fackler
Date Nov. 22, 2016, 3:01 a.m.
Message ID <de8e9f6a830166fe1cdb.1479783696@imladris.local>
Download mbox | patch
Permalink /patch/17677/
State Accepted
Headers show

Comments

Augie Fackler - Nov. 22, 2016, 3:01 a.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1479783083 18000
#      Mon Nov 21 21:51:23 2016 -0500
# Node ID de8e9f6a830166fe1cdb14bca0433fa328681ece
# Parent  c84baff8c3d45579fc0cb03492ced5c8f745749c
dispatch: stop supporting non-use of @command

We said we'd delete this after 3.8. It's time.
Yuya Nishihara - Nov. 22, 2016, 1:34 p.m.
On Mon, 21 Nov 2016 22:01:36 -0500, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1479783083 18000
> #      Mon Nov 21 21:51:23 2016 -0500
> # Node ID de8e9f6a830166fe1cdb14bca0433fa328681ece
> # Parent  c84baff8c3d45579fc0cb03492ced5c8f745749c
> dispatch: stop supporting non-use of @command

Queued with delight.

> @@ -3588,7 +3588,7 @@ def extsetup(ui):
>          for cmd, entry in cmdtable.iteritems():
>              cmd = cmdutil.parsealiases(cmd)[0]
>              func = entry[0]
> -            if dispatch._cmdattr(ui, cmd, func, 'norepo'):
> +            if func.norepo:

dropped unused import

> @@ -1515,43 +1515,6 @@ Test compatibility with extension comman
>    $ hg init deprecated
>    $ cd deprecated

and removed remainder of the test repository.

Patch

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -3588,7 +3588,7 @@  def extsetup(ui):
         for cmd, entry in cmdtable.iteritems():
             cmd = cmdutil.parsealiases(cmd)[0]
             func = entry[0]
-            if dispatch._cmdattr(ui, cmd, func, 'norepo'):
+            if func.norepo:
                 continue
             entry = extensions.wrapcommand(cmdtable, cmd, mqcommand)
             entry[1].extend(mqopt)
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -714,14 +714,6 @@  def _checkshellalias(lui, ui, args):
         return lambda: runcommand(lui, None, cmd, args[:1], ui, options, d,
                                   [], {})
 
-def _cmdattr(ui, cmd, func, attr):
-    try:
-        return getattr(func, attr)
-    except AttributeError:
-        ui.deprecwarn("missing attribute '%s', use @command decorator "
-                      "to register '%s'" % (attr, cmd), '3.8')
-        return False
-
 _loaded = set()
 
 # list of (objname, loadermod, loadername) tuple:
@@ -854,7 +846,7 @@  def _dispatch(req):
     with profiling.maybeprofile(lui):
         repo = None
         cmdpats = args[:]
-        if not _cmdattr(ui, cmd, func, 'norepo'):
+        if not func.norepo:
             # use the repo from the request only if we don't have -R
             if not rpath and not cwd:
                 repo = req.repo
@@ -877,9 +869,8 @@  def _dispatch(req):
                 except error.RepoError:
                     if rpath and rpath[-1]: # invalid -R path
                         raise
-                    if not _cmdattr(ui, cmd, func, 'optionalrepo'):
-                        if (_cmdattr(ui, cmd, func, 'inferrepo') and
-                            args and not path):
+                    if not func.optionalrepo:
+                        if func.inferrepo and args and not path:
                             # try to infer -R from command args
                             repos = map(cmdutil.findrepo, args)
                             guess = repos[0]
diff --git a/tests/test-extension.t b/tests/test-extension.t
--- a/tests/test-extension.t
+++ b/tests/test-extension.t
@@ -1515,43 +1515,6 @@  Test compatibility with extension comman
   $ hg init deprecated
   $ cd deprecated
 
-  $ cat <<EOF > deprecatedcmd.py
-  > def deprecatedcmd(repo, ui):
-  >     pass
-  > cmdtable = {
-  >     'deprecatedcmd': (deprecatedcmd, [], ''),
-  > }
-  > EOF
-  $ cat <<EOF > .hg/hgrc
-  > [extensions]
-  > deprecatedcmd = `pwd`/deprecatedcmd.py
-  > mq = !
-  > hgext.mq = !
-  > hgext/mq = !
-  > [alias]
-  > deprecatedalias = deprecatedcmd
-  > EOF
-
-  $ hg deprecatedcmd
-  devel-warn: missing attribute 'norepo', use @command decorator to register 'deprecatedcmd'
-  (compatibility will be dropped after Mercurial-3.8, update your code.) at: * (glob)
-
-  $ hg deprecatedalias
-  devel-warn: missing attribute 'norepo', use @command decorator to register 'deprecatedalias'
-  (compatibility will be dropped after Mercurial-3.8, update your code.) at: * (glob)
-
- no warning unless command is executed:
-
-  $ hg paths
-
- but mq iterates over command table:
-
-  $ hg --config extensions.mq= paths
-  devel-warn: missing attribute 'norepo', use @command decorator to register 'deprecatedcmd'
-  (compatibility will be dropped after Mercurial-3.8, update your code.) at: * (glob)
-
-  $ cd ..
-
 Test synopsis and docstring extending
 
   $ hg init exthelp