diff mercurial/revset.py @ 28892:0c135f37c6f8

parser: construct alias object by rule-set class It was odd that the revsetalias did the whole parsing stuff in __init__(). Instead, this patch adds a factory function to the aliasrules class, and makes the alias (= revsetalias) class a plain-old value object.
author Yuya Nishihara <yuya@tcha.org>
date Mon, 29 Feb 2016 18:33:30 +0900
parents 2e9f5453ab5a
children ee11167fe1da
line wrap: on
line diff
--- a/mercurial/revset.py	Fri Apr 08 16:42:43 2016 +0200
+++ b/mercurial/revset.py	Mon Feb 29 18:33:30 2016 +0900
@@ -2256,31 +2256,6 @@
     _parse = staticmethod(_parsealias)
     _getlist = staticmethod(getlist)
 
-class revsetalias(object):
-    # whether own `error` information is already shown or not.
-    # this avoids showing same warning multiple times at each `findaliases`.
-    warned = False
-
-    def __init__(self, name, value):
-        '''Aliases like:
-
-        h = heads(default)
-        b($1) = ancestors($1) - ancestors(default)
-        '''
-        r = _aliasrules._builddecl(name)
-        self.name, self.tree, self.args, self.error = r
-        if self.error:
-            self.error = _('failed to parse the declaration of revset alias'
-                           ' "%s": %s') % (self.name, self.error)
-            return
-
-        try:
-            self.replacement = _aliasrules._builddefn(value, self.args)
-        except error.ParseError as inst:
-            self.error = _('failed to parse the definition of revset alias'
-                           ' "%s": %s') % (self.name,
-                                           parser.parseerrordetail(inst))
-
 def _getalias(aliases, tree):
     """If tree looks like an unexpanded alias, return it. Return None
     otherwise.
@@ -2314,7 +2289,7 @@
     """Expand aliases in tree, recursively.
 
     'aliases' is a dictionary mapping user defined aliases to
-    revsetalias objects.
+    alias objects.
     """
     if not isinstance(tree, tuple):
         # Do not expand raw strings
@@ -2347,7 +2322,7 @@
 def findaliases(ui, tree, showwarning=None):
     aliases = {}
     for k, v in ui.configitems('revsetalias'):
-        alias = revsetalias(k, v)
+        alias = _aliasrules.build(k, v)
         aliases[alias.name] = alias
     tree = _expandaliases(aliases, tree, [], {})
     if showwarning: