mercurial/commands.py
changeset 29917 9cb950276d27
parent 29916 1c1c2bce2f97
child 29918 770128405002
--- a/mercurial/commands.py	Sun Aug 21 12:04:08 2016 +0900
+++ b/mercurial/commands.py	Sun Aug 21 12:33:57 2016 +0900
@@ -3511,13 +3511,16 @@
                                                              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 @@
         ('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)