[PATCH 2 of 4] revset: construct arguments of only() against matched tree

Yuya Nishihara yuya at tcha.org
Thu May 5 03:57:33 EDT 2016


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1462157448 -32400
#      Mon May 02 11:50:48 2016 +0900
# Node ID 8c9a75f74134dcb4479a873ad7208add62075704
# Parent  52b774a9a39cf7ea35a68e6f9100c6e07c45e384
revset: construct arguments of only() against matched tree

Since _isonly() knows the structure of 'revs' and 'bases', it should be
slightly easier to understand than destructuring 'ta' and 'tb'.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2073,15 +2073,20 @@ methods = {
     "parentpost": p1,
 }
 
-def _isonly(revs, bases):
-    return (
-        revs is not None
+def _matchonly(revs, bases):
+    """
+    >>> f = lambda *args: _matchonly(*map(parse, args))
+    >>> f('ancestors(A)', 'not ancestors(B)')
+    ('list', ('symbol', 'A'), ('symbol', 'B'))
+    """
+    if (revs is not None
         and revs[0] == 'func'
         and getstring(revs[1], _('not a symbol')) == 'ancestors'
         and bases is not None
         and bases[0] == 'not'
         and bases[1][0] == 'func'
-        and getstring(bases[1][1], _('not a symbol')) == 'ancestors')
+        and getstring(bases[1][1], _('not a symbol')) == 'ancestors'):
+        return ('list', revs[2], bases[1][2])
 
 def optimize(x, small):
     if x is None:
@@ -2120,10 +2125,9 @@ def optimize(x, small):
         w = min(wa, wb)
 
         # (::x and not ::y)/(not ::y and ::x) have a fast path
-        if _isonly(ta, tb):
-            return w, ('func', ('symbol', 'only'), ('list', ta[2], tb[1][2]))
-        if _isonly(tb, ta):
-            return w, ('func', ('symbol', 'only'), ('list', tb[2], ta[1][2]))
+        tm = _matchonly(ta, tb) or _matchonly(tb, ta)
+        if tm:
+            return w, ('func', ('symbol', 'only'), tm)
 
         if tb is not None and tb[0] == 'not':
             return wa, ('difference', ta, tb[1])


More information about the Mercurial-devel mailing list