[PATCH 1 of 4] revset: unnest isonly() closure from optimize()

Yuya Nishihara yuya at tcha.org
Thu May 5 07:57:32 UTC 2016


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1462156046 -32400
#      Mon May 02 11:27:26 2016 +0900
# Node ID 52b774a9a39cf7ea35a68e6f9100c6e07c45e384
# Parent  e0e72d67a8cd370218453ca0444e02aadabd56a8
revset: unnest isonly() closure from optimize()

There were no variables to be captured.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2073,6 +2073,16 @@ methods = {
     "parentpost": p1,
 }
 
+def _isonly(revs, bases):
+    return (
+        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')
+
 def optimize(x, small):
     if x is None:
         return 0, x
@@ -2107,22 +2117,12 @@ def optimize(x, small):
     elif op == 'and':
         wa, ta = optimize(x[1], True)
         wb, tb = optimize(x[2], True)
+        w = min(wa, wb)
 
         # (::x and not ::y)/(not ::y and ::x) have a fast path
-        def isonly(revs, bases):
-            return (
-                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')
-
-        w = min(wa, wb)
-        if isonly(ta, tb):
+        if _isonly(ta, tb):
             return w, ('func', ('symbol', 'only'), ('list', ta[2], tb[1][2]))
-        if isonly(tb, ta):
+        if _isonly(tb, ta):
             return w, ('func', ('symbol', 'only'), ('list', tb[2], ta[1][2]))
 
         if tb is not None and tb[0] == 'not':


More information about the Mercurial-devel mailing list