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".
--- 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)
--- a/tests/test-completion.t Sun Aug 21 12:04:08 2016 +0900
+++ b/tests/test-completion.t Sun Aug 21 12:33:57 2016 +0900
@@ -269,7 +269,7 @@
debugrebuildfncache:
debugrename: rev
debugrevlog: changelog, manifest, dir, dump
- debugrevspec: optimize
+ debugrevspec: optimize, show-stage
debugsetparents:
debugsub: rev
debugsuccessorssets:
--- a/tests/test-revset.t Sun Aug 21 12:04:08 2016 +0900
+++ b/tests/test-revset.t Sun Aug 21 12:33:57 2016 +0900
@@ -489,6 +489,56 @@
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.