[PATCH 1 of 3] dispatch: make cmdalias forward command attributes to function

Yuya Nishihara yuya at tcha.org
Thu Mar 24 11:27:27 EDT 2016


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1457881612 -32400
#      Mon Mar 14 00:06:52 2016 +0900
# Node ID 748200cca34890204c0a82fd6c6f8416d902e111
# Parent  ca38d993b1b6fc65fbeeba1cb743802ad0092580
dispatch: make cmdalias forward command attributes to function

This delays resolution of command attributes so that missing attributes
can be warned only when necessary.

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -437,9 +437,6 @@ class cmdalias(object):
         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 @@ class cmdalias(object):
                 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 @@ class cmdalias(object):
             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


More information about the Mercurial-devel mailing list