dispatch: make cmdalias forward command attributes to function
authorYuya Nishihara <yuya@tcha.org>
Mon, 14 Mar 2016 00:06:52 +0900
changeset 28621 d856e85a8a7a
parent 28620 759d167f75cf
child 28622 527cf881d000
dispatch: make cmdalias forward command attributes to function This delays resolution of command attributes so that missing attributes can be warned only when necessary.
mercurial/dispatch.py
--- a/mercurial/dispatch.py	Sun Mar 20 17:18:06 2016 -0700
+++ b/mercurial/dispatch.py	Mon Mar 14 00:06:52 2016 +0900
@@ -437,9 +437,6 @@
         self.args = []
         self.opts = []
         self.help = ''
-        self.norepo = True
-        self.optionalrepo = False
-        self.inferrepo = False
         self.badalias = None
         self.unknowncmd = False
 
@@ -501,12 +498,6 @@
                 self.fn, self.opts = tableentry
 
             self.args = aliasargs(self.fn, args)
-            if not self.fn.norepo:
-                self.norepo = False
-            if self.fn.optionalrepo:
-                self.optionalrepo = True
-            if self.fn.inferrepo:
-                self.inferrepo = True
             if self.help.startswith("hg " + cmd):
                 # drop prefix in old-style help lines so hg shows the alias
                 self.help = self.help[4 + len(cmd):]
@@ -520,6 +511,14 @@
             self.badalias = (_("alias '%s' resolves to ambiguous command '%s'")
                              % (self.name, cmd))
 
+    def __getattr__(self, name):
+        adefaults = {'norepo': True, 'optionalrepo': False, 'inferrepo': False}
+        if name not in adefaults:
+            raise AttributeError(name)
+        if self.badalias or util.safehasattr(self, 'shell'):
+            return adefaults[name]
+        return getattr(self.fn, name)
+
     def __call__(self, ui, *args, **opts):
         if self.badalias:
             hint = None