[PATCH 2 of 3] revset: make analyze() a separate step from optimize()

Yuya Nishihara yuya at tcha.org
Wed Sep 7 10:44:16 EDT 2016


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1471746597 -32400
#      Sun Aug 21 11:29:57 2016 +0900
# Node ID eab0f0cbd818cc2bb325cac0e7d61483b63d5ae6
# Parent  2577e0fe3de10b2021445872fb318b6b2a28d596
revset: make analyze() a separate step from optimize()

This will allow us to evaluate unoptimized tree and compare the result with
optimized one.

The private _analyze() function isn't renamed since I'll add more parameters
to it.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3530,6 +3530,7 @@ def debugrevspec(ui, repo, expr, **opts)
         if newtree != tree:
             ui.note(("* concatenated:\n"), revset.prettyformat(newtree), "\n")
         if opts["optimize"]:
+            newtree = revset.analyze(newtree)
             optimizedtree = revset.optimize(newtree)
             ui.note(("* optimized:\n"),
                     revset.prettyformat(optimizedtree), "\n")
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2343,12 +2343,6 @@ def _fixops(x):
     return (op,) + tuple(_fixops(y) for y in x[1:])
 
 def _analyze(x):
-    """Transform raw parsed tree to evaluatable tree which can be fed to
-    optimize() or getset()
-
-    All pseudo operations should be mapped to real operations or functions
-    defined in methods or symbols table respectively.
-    """
     if x is None:
         return x
 
@@ -2399,11 +2393,16 @@ def _analyze(x):
         return (op, x[1], _analyze(x[2]))
     raise ValueError('invalid operator %r' % op)
 
+def analyze(x):
+    """Transform raw parsed tree to evaluatable tree which can be fed to
+    optimize() or getset()
+
+    All pseudo operations should be mapped to real operations or functions
+    defined in methods or symbols table respectively.
+    """
+    return _analyze(x)
+
 def _optimize(x, small):
-    """Optimize evaluatable tree
-
-    All pseudo operations should be transformed beforehand.
-    """
     if x is None:
         return 0, x
 
@@ -2505,7 +2504,10 @@ def _optimize(x, small):
     raise ValueError('invalid operator %r' % op)
 
 def optimize(tree):
-    tree = _analyze(tree)
+    """Optimize evaluatable tree
+
+    All pseudo operations should be transformed beforehand.
+    """
     _weight, newtree = _optimize(tree, small=True)
     return newtree
 
@@ -2619,6 +2621,7 @@ def _makematcher(ui, tree, repo):
     if ui:
         tree = expandaliases(ui, tree, showwarning=ui.warn)
     tree = foldconcat(tree)
+    tree = analyze(tree)
     tree = optimize(tree)
     posttreebuilthook(tree, repo)
     def mfunc(repo, subset=None):
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -54,7 +54,7 @@ these predicates use '\0' as a separator
   >         tree = revset.parse(expr, lookup=repo.__contains__)
   >         ui.note(revset.prettyformat(tree), "\n")
   >         if opts["optimize"]:
-  >             opttree = revset.optimize(tree)
+  >             opttree = revset.optimize(revset.analyze(tree))
   >             ui.note("* optimized:\n", revset.prettyformat(opttree), "\n")
   >     func = revset.match(ui, expr, repo)
   >     revs = func(repo)


More information about the Mercurial-devel mailing list