Mercurial > hg
comparison mercurial/commands.py @ 29913:9cb950276d27
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".
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 21 Aug 2016 12:33:57 +0900 |
parents | 1c1c2bce2f97 |
children | 770128405002 |
comparison
equal
deleted
inserted
replaced
29912:1c1c2bce2f97 | 29913:9cb950276d27 |
---|---|
3509 + fmt % pcfmt(nump2, numdeltas)) | 3509 + fmt % pcfmt(nump2, numdeltas)) |
3510 ui.write(('deltas against other : ') + fmt % pcfmt(numother, | 3510 ui.write(('deltas against other : ') + fmt % pcfmt(numother, |
3511 numdeltas)) | 3511 numdeltas)) |
3512 | 3512 |
3513 @command('debugrevspec', | 3513 @command('debugrevspec', |
3514 [('', 'optimize', None, _('print parsed tree after optimizing'))], | 3514 [('', 'optimize', None, _('print parsed tree after optimizing')), |
3515 ('p', 'show-stage', [], | |
3516 _('print parsed tree at the given stage'), _('NAME')), | |
3517 ], | |
3515 ('REVSPEC')) | 3518 ('REVSPEC')) |
3516 def debugrevspec(ui, repo, expr, **opts): | 3519 def debugrevspec(ui, repo, expr, **opts): |
3517 """parse and apply a revision specification | 3520 """parse and apply a revision specification |
3518 | 3521 |
3519 Use --verbose to print the parsed tree before and after aliases | 3522 Use -p/--show-stage option to print the parsed tree at the given stages. |
3520 expansion. | 3523 Use -p all to print tree at every stage. |
3521 """ | 3524 """ |
3522 stages = [ | 3525 stages = [ |
3523 ('parsed', lambda tree: tree), | 3526 ('parsed', lambda tree: tree), |
3524 ('expanded', lambda tree: revset.expandaliases(ui, tree)), | 3527 ('expanded', lambda tree: revset.expandaliases(ui, tree)), |
3525 ('concatenated', revset.foldconcat), | 3528 ('concatenated', revset.foldconcat), |
3526 ('analyzed', revset.analyze), | 3529 ('analyzed', revset.analyze), |
3527 ('optimized', revset.optimize), | 3530 ('optimized', revset.optimize), |
3528 ] | 3531 ] |
3529 | 3532 stagenames = set(n for n, f in stages) |
3530 showalways = set(['parsed']) | 3533 |
3531 showchanged = set(['expanded', 'concatenated']) | 3534 showalways = set() |
3532 if opts['optimize']: | 3535 showchanged = set() |
3533 showalways.add('optimized') | 3536 if ui.verbose and not opts['show_stage']: |
3537 # show parsed tree by --verbose (deprecated) | |
3538 showalways.add('parsed') | |
3539 showchanged.update(['expanded', 'concatenated']) | |
3540 if opts['optimize']: | |
3541 showalways.add('optimized') | |
3542 if opts['show_stage'] and opts['optimize']: | |
3543 raise error.Abort(_('cannot use --optimize with --show-stage')) | |
3544 if opts['show_stage'] == ['all']: | |
3545 showalways.update(stagenames) | |
3546 else: | |
3547 for n in opts['show_stage']: | |
3548 if n not in stagenames: | |
3549 raise error.Abort(_('invalid stage name: %s') % n) | |
3550 showalways.update(opts['show_stage']) | |
3534 | 3551 |
3535 printedtree = None | 3552 printedtree = None |
3536 tree = revset.parse(expr, lookup=repo.__contains__) | 3553 tree = revset.parse(expr, lookup=repo.__contains__) |
3537 for n, f in stages: | 3554 for n, f in stages: |
3538 tree = f(tree) | 3555 tree = f(tree) |
3539 if n in showalways or (n in showchanged and tree != printedtree): | 3556 if n in showalways or (n in showchanged and tree != printedtree): |
3540 if n != 'parsed': | 3557 if opts['show_stage'] or n != 'parsed': |
3541 ui.note(("* %s:\n") % n) | 3558 ui.write(("* %s:\n") % n) |
3542 ui.note(revset.prettyformat(tree), "\n") | 3559 ui.write(revset.prettyformat(tree), "\n") |
3543 printedtree = tree | 3560 printedtree = tree |
3544 | 3561 |
3545 func = revset.match(ui, expr, repo) | 3562 func = revset.match(ui, expr, repo) |
3546 revs = func(repo) | 3563 revs = func(repo) |
3547 if ui.verbose: | 3564 if ui.verbose: |