changeset 28896:4c76a032ec7e

parser: reorder alias expansion routine to return early I think it improves readability to move trivial cases first, and unindent blocks.
author Yuya Nishihara <yuya@tcha.org>
date Tue, 29 Mar 2016 16:19:31 +0900
parents 4bf9ed7a260e
children c1f254138f44
files mercurial/parser.py
diffstat 1 files changed, 23 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/parser.py	Mon Feb 29 22:15:44 2016 +0900
+++ b/mercurial/parser.py	Tue Mar 29 16:19:31 2016 +0900
@@ -509,31 +509,29 @@
         if not isinstance(tree, tuple):
             return tree
         a = cls._getalias(aliases, tree)
-        if a is not None:
-            if a.error:
-                raise error.Abort(a.error)
-            if a in expanding:
-                raise error.ParseError(_('infinite expansion of %(section)s '
-                                         '"%(name)s" detected')
-                                       % {'section': cls._section,
-                                          'name': a.name})
-            expanding.append(a)
-            if a.name not in cache:
-                cache[a.name] = cls._expand(aliases, a.replacement, expanding,
-                                            cache)
-            result = cache[a.name]
-            expanding.pop()
-            if a.args is not None:
-                l = cls._getlist(tree[2])
-                if len(l) != len(a.args):
-                    raise error.ParseError(_('invalid number of arguments: %d')
-                                           % len(l))
-                l = [cls._expand(aliases, t, [], cache) for t in l]
-                result = cls._expandargs(result, dict(zip(a.args, l)))
-        else:
-            result = tuple(cls._expand(aliases, t, expanding, cache)
-                           for t in tree)
-        return result
+        if a is None:
+            return tuple(cls._expand(aliases, t, expanding, cache)
+                         for t in tree)
+        if a.error:
+            raise error.Abort(a.error)
+        if a in expanding:
+            raise error.ParseError(_('infinite expansion of %(section)s '
+                                     '"%(name)s" detected')
+                                   % {'section': cls._section, 'name': a.name})
+        expanding.append(a)
+        if a.name not in cache:
+            cache[a.name] = cls._expand(aliases, a.replacement, expanding,
+                                        cache)
+        result = cache[a.name]
+        expanding.pop()
+        if a.args is None:
+            return result
+        l = cls._getlist(tree[2])
+        if len(l) != len(a.args):
+            raise error.ParseError(_('invalid number of arguments: %d')
+                                   % len(l))
+        l = [cls._expand(aliases, t, [], cache) for t in l]
+        return cls._expandargs(result, dict(zip(a.args, l)))
 
     @classmethod
     def expand(cls, aliases, tree):