Patchwork [5,of,7] parser: reorder alias expansion routine to return early

login
register
mail settings
Submitter Yuya Nishihara
Date April 13, 2016, 3:55 p.m.
Message ID <b50d0a0a24d9cdd99531.1460562917@mimosa>
Download mbox | patch
Permalink /patch/14585/
State Accepted
Commit 4c76a032ec7e4186549b68819e197db2498dfa90
Headers show

Comments

Yuya Nishihara - April 13, 2016, 3:55 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1459235971 -32400
#      Tue Mar 29 16:19:31 2016 +0900
# Node ID b50d0a0a24d9cdd99531cf7172ce4b0d0c79c9f2
# Parent  f71d1db9f483558c881e55f0f20b20a97b727cd4
parser: reorder alias expansion routine to return early

I think it improves readability to move trivial cases first, and unindent
blocks.

Patch

diff --git a/mercurial/parser.py b/mercurial/parser.py
--- a/mercurial/parser.py
+++ b/mercurial/parser.py
@@ -509,31 +509,29 @@  class basealiasrules(object):
         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):