Patchwork [3,of,6] alias: provide "unknowncmd" flag to tell help to look for disabled command

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 14, 2014, 2:31 a.m.
Message ID <cb7cc831f040ddd6a880.1407983485@mimosa>
Download mbox | patch
Permalink /patch/5389/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 14, 2014, 2:31 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1407925722 -32400
#      Wed Aug 13 19:28:42 2014 +0900
# Node ID cb7cc831f040ddd6a880157d1c6c6ddd0fc5c3fb
# Parent  b884588ea7541d7c64d7e7143ce6349ab3853981
alias: provide "unknowncmd" flag to tell help to look for disabled command

This patch prepares for breaking the call loop: help.help_() -> cmdalias() ->
commands.help_() -> help.help_().

Patch

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -343,6 +343,7 @@  class cmdalias(object):
         self.norepo = True
         self.optionalrepo = False
         self.badalias = None
+        self.unknowncmd = False
 
         try:
             aliases, entry = cmdutil.findcmd(self.name, cmdtable)
@@ -415,16 +416,9 @@  class cmdalias(object):
             self.__doc__ = self.fn.__doc__
 
         except error.UnknownCommand:
-            def fn(ui, *args):
-                try:
-                    # check if the command is in a disabled extension
-                    commands.help_(ui, cmd, unknowncmd=True)
-                except error.UnknownCommand:
-                    pass
-                return -1
-            self.fn = fn
             self.badalias = (_("alias '%s' resolves to unknown command '%s'")
                              % (self.name, cmd))
+            self.unknowncmd = True
         except error.AmbiguousCommand:
             self.badalias = (_("alias '%s' resolves to ambiguous command '%s'")
                              % (self.name, cmd))
@@ -432,8 +426,12 @@  class cmdalias(object):
     def __call__(self, ui, *args, **opts):
         if self.badalias:
             ui.warn(self.badalias + '\n')
-            if self.fn:
-                return self.fn(ui, *args, **opts)
+            if self.unknowncmd:
+                try:
+                    # check if the command is in a disabled extension
+                    commands.help_(ui, self.cmdname, unknowncmd=True)
+                except error.UnknownCommand:
+                    pass
             return -1
         if self.shadows:
             ui.debug("alias '%s' shadows command '%s'\n" %