[PATCH 3 of 4] debugrevspec: add option to print parsed tree at given stages

Yuya Nishihara yuya at tcha.org
Thu Sep 8 11:14:25 EDT 2016


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1471750437 -32400
#      Sun Aug 21 12:33:57 2016 +0900
# Node ID 737f256f394d4401e554413fc77cfc85b8337d32
# Parent  42823004ac293802357b2ec9b7821d5e8ea515f9
debugrevspec: add option to print parsed tree at given stages

"-p <stage>" is useful for investigating parsing stages. With -p option, a
transformed tree is printed no matter if it is changed or not, which allows
us to know valid stage names by "-p all".

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3511,13 +3511,16 @@ def debugrevlog(ui, repo, file_=None, **
                                                              numdeltas))
 
 @command('debugrevspec',
-    [('', 'optimize', None, _('print parsed tree after optimizing'))],
+    [('', 'optimize', None, _('print parsed tree after optimizing')),
+     ('p', 'show-stage', [],
+      _('print parsed tree at the given stage'), _('NAME')),
+     ],
     ('REVSPEC'))
 def debugrevspec(ui, repo, expr, **opts):
     """parse and apply a revision specification
 
-    Use --verbose to print the parsed tree before and after aliases
-    expansion.
+    Use -p/--show-stage option to print the parsed tree at the given stages.
+    Use -p all to print tree at every stage.
     """
     stages = [
         ('parsed', lambda tree: tree),
@@ -3526,20 +3529,34 @@ def debugrevspec(ui, repo, expr, **opts)
         ('analyzed', revset.analyze),
         ('optimized', revset.optimize),
     ]
-
-    showalways = set(['parsed'])
-    showchanged = set(['expanded', 'concatenated'])
-    if opts['optimize']:
-        showalways.add('optimized')
+    stagenames = set(n for n, f in stages)
+
+    showalways = set()
+    showchanged = set()
+    if ui.verbose and not opts['show_stage']:
+        # show parsed tree by --verbose (deprecated)
+        showalways.add('parsed')
+        showchanged.update(['expanded', 'concatenated'])
+        if opts['optimize']:
+            showalways.add('optimized')
+    if opts['show_stage'] and opts['optimize']:
+        raise error.Abort(_('cannot use --optimize with --show-stage'))
+    if opts['show_stage'] == ['all']:
+        showalways.update(stagenames)
+    else:
+        for n in opts['show_stage']:
+            if n not in stagenames:
+                raise error.Abort(_('invalid stage name: %s') % n)
+        showalways.update(opts['show_stage'])
 
     printedtree = None
     tree = revset.parse(expr, lookup=repo.__contains__)
     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")
+            if opts['show_stage'] or n != 'parsed':
+                ui.write(("* %s:\n") % n)
+            ui.write(revset.prettyformat(tree), "\n")
             printedtree = tree
 
     func = revset.match(ui, expr, repo)
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -269,7 +269,7 @@ Show all commands + options
   debugrebuildfncache: 
   debugrename: rev
   debugrevlog: changelog, manifest, dir, dump
-  debugrevspec: optimize
+  debugrevspec: optimize, show-stage
   debugsetparents: 
   debugsub: rev
   debugsuccessorssets: 
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -489,6 +489,56 @@ keyword arguments
   hg: parse error: can't use a key-value pair in this context
   [255]
 
+parsed tree at stages:
+
+  $ hg debugrevspec -p all '()'
+  * parsed:
+  (group
+    None)
+  * expanded:
+  (group
+    None)
+  * concatenated:
+  (group
+    None)
+  * analyzed:
+  None
+  * optimized:
+  None
+  hg: parse error: missing argument
+  [255]
+
+  $ hg debugrevspec -p parsed -p analyzed -p optimized '(0|1)-1'
+  * parsed:
+  (minus
+    (group
+      (or
+        ('symbol', '0')
+        ('symbol', '1')))
+    ('symbol', '1'))
+  * analyzed:
+  (and
+    (or
+      ('symbol', '0')
+      ('symbol', '1'))
+    (not
+      ('symbol', '1')))
+  * optimized:
+  (difference
+    (func
+      ('symbol', '_list')
+      ('string', '0\x001'))
+    ('symbol', '1'))
+  0
+
+  $ hg debugrevspec -p unknown '0'
+  abort: invalid stage name: unknown
+  [255]
+
+  $ hg debugrevspec -p all --optimize '0'
+  abort: cannot use --optimize with --show-stage
+  [255]
+
 Test that symbols only get parsed as functions if there's an opening
 parenthesis.
 


More information about the Mercurial-devel mailing list