Patchwork [2,of,5] parser: make _getalias() return (alias, pattern-args) pair

login
register
mail settings
Submitter Yuya Nishihara
Date April 14, 2016, 3:42 p.m.
Message ID <7ef4bb3dda5e643c2e32.1460648571@mimosa>
Download mbox | patch
Permalink /patch/14622/
State Accepted
Headers show

Comments

Yuya Nishihara - April 14, 2016, 3:42 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1459239671 -32400
#      Tue Mar 29 17:21:11 2016 +0900
# Node ID 7ef4bb3dda5e643c2e32d36c1d77dac0115e8469
# Parent  8bfa28f6c74b2049c018b23253d4587d811e01d3
parser: make _getalias() return (alias, pattern-args) pair

This allows us to factor out a function that extracts a function (name, args)
pair. See the next patch for why.

Patch

diff --git a/mercurial/parser.py b/mercurial/parser.py
--- a/mercurial/parser.py
+++ b/mercurial/parser.py
@@ -473,8 +473,8 @@  class basealiasrules(object):
 
     @classmethod
     def _getalias(cls, aliases, tree):
-        """If tree looks like an unexpanded alias, return it. Return None
-        otherwise.
+        """If tree looks like an unexpanded alias, return (alias, pattern-args)
+        pair. Return None otherwise.
         """
         if not isinstance(tree, tuple):
             return None
@@ -482,12 +482,12 @@  class basealiasrules(object):
             name = tree[1]
             a = aliases.get(name)
             if a and a.args is None:
-                return a
+                return a, None
         if tree[0] == cls._funcnode and tree[1][0] == cls._symbolnode:
             name = tree[1][1]
             a = aliases.get(name)
             if a and a.args is not None:
-                return a
+                return a, cls._getlist(tree[2])
         return None
 
     @classmethod
@@ -506,10 +506,11 @@  class basealiasrules(object):
     def _expand(cls, aliases, tree, expanding, cache):
         if not isinstance(tree, tuple):
             return tree
-        a = cls._getalias(aliases, tree)
-        if a is None:
+        r = cls._getalias(aliases, tree)
+        if r is None:
             return tuple(cls._expand(aliases, t, expanding, cache)
                          for t in tree)
+        a, l = r
         if a.error:
             raise error.Abort(a.error)
         if a in expanding:
@@ -526,7 +527,6 @@  class basealiasrules(object):
         if a.args is None:
             return result
         # substitute function arguments in replacement tree
-        l = cls._getlist(tree[2])
         if len(l) != len(a.args):
             raise error.ParseError(_('invalid number of arguments: %d')
                                    % len(l))