# HG changeset patch # User Yuya Nishihara # Date 1456741455 -32400 # Node ID ee11167fe1da9ea8d931f703a8255251d5723434 # Parent 0c135f37c6f8097d0a53295a25995abaab4d30cf parser: extract helper that creates a dict of aliases This will be common between revset and templater. The local variable 'alias' is renamed to 'a' to avoid shadowing the global 'alias' class. diff -r 0c135f37c6f8 -r ee11167fe1da mercurial/parser.py --- a/mercurial/parser.py Mon Feb 29 18:33:30 2016 +0900 +++ b/mercurial/parser.py Mon Feb 29 19:24:15 2016 +0900 @@ -462,3 +462,13 @@ if err: err = efmt % {'section': cls._section, 'name': name, 'error': err} return alias(name, tree, args, err, repl) + + @classmethod + def buildmap(cls, items): + """Parse a list of alias (name, replacement) pairs into a dict of + alias objects""" + aliases = {} + for decl, defn in items: + a = cls.build(decl, defn) + aliases[a.name] = a + return aliases diff -r 0c135f37c6f8 -r ee11167fe1da mercurial/revset.py --- a/mercurial/revset.py Mon Feb 29 18:33:30 2016 +0900 +++ b/mercurial/revset.py Mon Feb 29 19:24:15 2016 +0900 @@ -2320,10 +2320,7 @@ return result def findaliases(ui, tree, showwarning=None): - aliases = {} - for k, v in ui.configitems('revsetalias'): - alias = _aliasrules.build(k, v) - aliases[alias.name] = alias + aliases = _aliasrules.buildmap(ui.configitems('revsetalias')) tree = _expandaliases(aliases, tree, [], {}) if showwarning: # warn about problematic (but not referred) aliases