# HG changeset patch # User Yuya Nishihara # Date 1457881612 -32400 # Node ID d856e85a8a7a1e3ff5e9d5c3df4497b95309e40f # Parent 759d167f75cf04e3a3691a418db7efa64b93e0fc 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 -r 759d167f75cf -r d856e85a8a7a 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