revset: make analyze() a separate step from optimize()
authorYuya Nishihara <yuya@tcha.org>
Sun, 21 Aug 2016 11:29:57 +0900
changeset 29909 371c2a39eead
parent 29908 e4b4168a4f1c
child 29910 41491cf936f2
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.
mercurial/commands.py
mercurial/revset.py
tests/test-revset.t
--- a/mercurial/commands.py	Sun Aug 07 14:35:03 2016 +0900
+++ b/mercurial/commands.py	Sun Aug 21 11:29:57 2016 +0900
@@ -3530,6 +3530,7 @@
         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")
--- a/mercurial/revset.py	Sun Aug 07 14:35:03 2016 +0900
+++ b/mercurial/revset.py	Sun Aug 21 11:29:57 2016 +0900
@@ -2343,12 +2343,6 @@
     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 @@
         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 @@
     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 @@
     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):
--- a/tests/test-revset.t	Sun Aug 07 14:35:03 2016 +0900
+++ b/tests/test-revset.t	Sun Aug 21 11:29:57 2016 +0900
@@ -54,7 +54,7 @@
   >         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)