##// END OF EJS Templates
debugrevspec: add option to verify optimized result...
Yuya Nishihara -
r29924:45bf56a8 default
parent child Browse files
Show More
@@ -3516,6 +3516,7 b' def debugrevlog(ui, repo, file_=None, **'
3516 ('p', 'show-stage', [],
3516 ('p', 'show-stage', [],
3517 _('print parsed tree at the given stage'), _('NAME')),
3517 _('print parsed tree at the given stage'), _('NAME')),
3518 ('', 'no-optimized', False, _('evaluate tree without optimization')),
3518 ('', 'no-optimized', False, _('evaluate tree without optimization')),
3519 ('', 'verify-optimized', False, _('verify optimized result')),
3519 ],
3520 ],
3520 ('REVSPEC'))
3521 ('REVSPEC'))
3521 def debugrevspec(ui, repo, expr, **opts):
3522 def debugrevspec(ui, repo, expr, **opts):
@@ -3523,6 +3524,9 b' def debugrevspec(ui, repo, expr, **opts)'
3523
3524
3524 Use -p/--show-stage option to print the parsed tree at the given stages.
3525 Use -p/--show-stage option to print the parsed tree at the given stages.
3525 Use -p all to print tree at every stage.
3526 Use -p all to print tree at every stage.
3527
3528 Use --verify-optimized to compare the optimized result with the unoptimized
3529 one. Returns 1 if the optimized result differs.
3526 """
3530 """
3527 stages = [
3531 stages = [
3528 ('parsed', lambda tree: tree),
3532 ('parsed', lambda tree: tree),
@@ -3533,6 +3537,9 b' def debugrevspec(ui, repo, expr, **opts)'
3533 ]
3537 ]
3534 if opts['no_optimized']:
3538 if opts['no_optimized']:
3535 stages = stages[:-1]
3539 stages = stages[:-1]
3540 if opts['verify_optimized'] and opts['no_optimized']:
3541 raise error.Abort(_('cannot use --verify-optimized with '
3542 '--no-optimized'))
3536 stagenames = set(n for n, f in stages)
3543 stagenames = set(n for n, f in stages)
3537
3544
3538 showalways = set()
3545 showalways = set()
@@ -3553,16 +3560,42 b' def debugrevspec(ui, repo, expr, **opts)'
3553 raise error.Abort(_('invalid stage name: %s') % n)
3560 raise error.Abort(_('invalid stage name: %s') % n)
3554 showalways.update(opts['show_stage'])
3561 showalways.update(opts['show_stage'])
3555
3562
3563 treebystage = {}
3556 printedtree = None
3564 printedtree = None
3557 tree = revset.parse(expr, lookup=repo.__contains__)
3565 tree = revset.parse(expr, lookup=repo.__contains__)
3558 for n, f in stages:
3566 for n, f in stages:
3559 tree = f(tree)
3567 treebystage[n] = tree = f(tree)
3560 if n in showalways or (n in showchanged and tree != printedtree):
3568 if n in showalways or (n in showchanged and tree != printedtree):
3561 if opts['show_stage'] or n != 'parsed':
3569 if opts['show_stage'] or n != 'parsed':
3562 ui.write(("* %s:\n") % n)
3570 ui.write(("* %s:\n") % n)
3563 ui.write(revset.prettyformat(tree), "\n")
3571 ui.write(revset.prettyformat(tree), "\n")
3564 printedtree = tree
3572 printedtree = tree
3565
3573
3574 if opts['verify_optimized']:
3575 arevs = revset.makematcher(treebystage['analyzed'])(repo)
3576 brevs = revset.makematcher(treebystage['optimized'])(repo)
3577 if ui.verbose:
3578 ui.note(("* analyzed set:\n"), revset.prettyformatset(arevs), "\n")
3579 ui.note(("* optimized set:\n"), revset.prettyformatset(brevs), "\n")
3580 arevs = list(arevs)
3581 brevs = list(brevs)
3582 if arevs == brevs:
3583 return 0
3584 ui.write(('--- analyzed\n'), label='diff.file_a')
3585 ui.write(('+++ optimized\n'), label='diff.file_b')
3586 sm = difflib.SequenceMatcher(None, arevs, brevs)
3587 for tag, alo, ahi, blo, bhi in sm.get_opcodes():
3588 if tag in ('delete', 'replace'):
3589 for c in arevs[alo:ahi]:
3590 ui.write('-%s\n' % c, label='diff.deleted')
3591 if tag in ('insert', 'replace'):
3592 for c in brevs[blo:bhi]:
3593 ui.write('+%s\n' % c, label='diff.inserted')
3594 if tag == 'equal':
3595 for c in arevs[alo:ahi]:
3596 ui.write(' %s\n' % c)
3597 return 1
3598
3566 func = revset.makematcher(tree)
3599 func = revset.makematcher(tree)
3567 revs = func(repo)
3600 revs = func(repo)
3568 if ui.verbose:
3601 if ui.verbose:
@@ -269,7 +269,7 b' Show all commands + options'
269 debugrebuildfncache:
269 debugrebuildfncache:
270 debugrename: rev
270 debugrename: rev
271 debugrevlog: changelog, manifest, dir, dump
271 debugrevlog: changelog, manifest, dir, dump
272 debugrevspec: optimize, show-stage, no-optimized
272 debugrevspec: optimize, show-stage, no-optimized, verify-optimized
273 debugsetparents:
273 debugsetparents:
274 debugsub: rev
274 debugsub: rev
275 debugsuccessorssets:
275 debugsuccessorssets:
@@ -554,6 +554,37 b' parsed tree at stages:'
554 abort: cannot use --optimize with --show-stage
554 abort: cannot use --optimize with --show-stage
555 [255]
555 [255]
556
556
557 verify optimized tree:
558
559 $ hg debugrevspec --verify '0|1'
560
561 $ hg debugrevspec --verify -v -p analyzed -p optimized 'r3232() & 2'
562 * analyzed:
563 (and
564 (func
565 ('symbol', 'r3232')
566 None)
567 ('symbol', '2'))
568 * optimized:
569 (and
570 ('symbol', '2')
571 (func
572 ('symbol', 'r3232')
573 None))
574 * analyzed set:
575 <baseset [2]>
576 * optimized set:
577 <baseset [2, 2]>
578 --- analyzed
579 +++ optimized
580 2
581 +2
582 [1]
583
584 $ hg debugrevspec --no-optimized --verify-optimized '0'
585 abort: cannot use --verify-optimized with --no-optimized
586 [255]
587
557 Test that symbols only get parsed as functions if there's an opening
588 Test that symbols only get parsed as functions if there's an opening
558 parenthesis.
589 parenthesis.
559
590
General Comments 0
You need to be logged in to leave comments. Login now