Patchwork [2,of,4] debugrevspec: transform and print parsed tree by stages

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 8, 2016, 3:14 p.m.
Message ID <42823004ac293802357b.1473347664@mimosa>
Download mbox | patch
Permalink /patch/16577/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 8, 2016, 3:14 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1471748648 -32400
#      Sun Aug 21 12:04:08 2016 +0900
# Node ID 42823004ac293802357b2ec9b7821d5e8ea515f9
# Parent  f3f3289bfa565f21e50b2f14d4ab4c6d0df349fd
debugrevspec: transform and print parsed tree by stages

Prepares for adding new option to print transformed tree at each stage.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3519,20 +3519,28 @@  def debugrevspec(ui, repo, expr, **opts)
     Use --verbose to print the parsed tree before and after aliases
     expansion.
     """
+    stages = [
+        ('parsed', lambda tree: tree),
+        ('expanded', lambda tree: revset.expandaliases(ui, tree)),
+        ('concatenated', revset.foldconcat),
+        ('analyzed', revset.analyze),
+        ('optimized', revset.optimize),
+    ]
+
+    showalways = set(['parsed'])
+    showchanged = set(['expanded', 'concatenated'])
+    if opts['optimize']:
+        showalways.add('optimized')
+
+    printedtree = None
     tree = revset.parse(expr, lookup=repo.__contains__)
-    ui.note(revset.prettyformat(tree), "\n")
-    newtree = revset.expandaliases(ui, tree)
-    if newtree != tree:
-        ui.note(("* expanded:\n"), revset.prettyformat(newtree), "\n")
-    tree = newtree
-    newtree = revset.foldconcat(tree)
-    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")
+    for n, f in stages:
+        tree = f(tree)
+        if n in showalways or (n in showchanged and tree != printedtree):
+            if n != 'parsed':
+                ui.note(("* %s:\n") % n)
+            ui.note(revset.prettyformat(tree), "\n")
+            printedtree = tree
 
     func = revset.match(ui, expr, repo)
     revs = func(repo)