diff mercurial/cmdutil.py @ 28313:aa73d6a5d9ea

dispatch: store norepo/optionalrepo/inferrepo attributes in function (API) This can eliminate import cycles and ugly push/pop of global variables at _checkshellalias(). Attributes of aliascmd are directly accessible. Because norepo/optionalrepo/inferrepo lists aren't populated, extensions examining them no longer work. That's why this patch removes these lists to signal the API incompatibility. This breaks 3rd-party extensions that are yet to be ported to @command decorator.
author Yuya Nishihara <yuya@tcha.org>
date Fri, 01 Jan 2016 22:16:25 +0900
parents c7f89ad87bae
children ebd0e86bdf89
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Sat Jan 09 20:04:03 2016 +0900
+++ b/mercurial/cmdutil.py	Fri Jan 01 22:16:25 2016 +0900
@@ -3270,24 +3270,13 @@
     def cmd(name, options=(), synopsis=None, norepo=False, optionalrepo=False,
             inferrepo=False):
         def decorator(func):
+            func.norepo = norepo
+            func.optionalrepo = optionalrepo
+            func.inferrepo = inferrepo
             if synopsis:
                 table[name] = func, list(options), synopsis
             else:
                 table[name] = func, list(options)
-
-            if norepo:
-                # Avoid import cycle.
-                import commands
-                commands.norepo += ' %s' % ' '.join(parsealiases(name))
-
-            if optionalrepo:
-                import commands
-                commands.optionalrepo += ' %s' % ' '.join(parsealiases(name))
-
-            if inferrepo:
-                import commands
-                commands.inferrepo += ' %s' % ' '.join(parsealiases(name))
-
             return func
         return decorator