Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/debugcommands.py @ 30972:85c3c879c43a
debugcommands: move 'debugrevspec' in the new module
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Thu, 02 Feb 2017 10:03:31 +0100 |
parents | f44b96aef81b |
children | 5b09e9bc0902 |
comparison
equal
deleted
inserted
replaced
30971:f44b96aef81b | 30972:85c3c879c43a |
---|---|
5 # This software may be used and distributed according to the terms of the | 5 # This software may be used and distributed according to the terms of the |
6 # GNU General Public License version 2 or any later version. | 6 # GNU General Public License version 2 or any later version. |
7 | 7 |
8 from __future__ import absolute_import | 8 from __future__ import absolute_import |
9 | 9 |
10 import difflib | |
10 import errno | 11 import errno |
11 import operator | 12 import operator |
12 import os | 13 import os |
13 import random | 14 import random |
14 import socket | 15 import socket |
47 policy, | 48 policy, |
48 pvec, | 49 pvec, |
49 pycompat, | 50 pycompat, |
50 repair, | 51 repair, |
51 revlog, | 52 revlog, |
53 revset, | |
52 scmutil, | 54 scmutil, |
53 setdiscovery, | 55 setdiscovery, |
54 simplemerge, | 56 simplemerge, |
57 smartset, | |
55 sslutil, | 58 sslutil, |
56 streamclone, | 59 streamclone, |
57 templater, | 60 templater, |
58 treediscovery, | 61 treediscovery, |
59 util, | 62 util, |
1737 ui.write(('deltas against p2 : ') | 1740 ui.write(('deltas against p2 : ') |
1738 + fmt % pcfmt(nump2, numdeltas)) | 1741 + fmt % pcfmt(nump2, numdeltas)) |
1739 ui.write(('deltas against other : ') + fmt % pcfmt(numother, | 1742 ui.write(('deltas against other : ') + fmt % pcfmt(numother, |
1740 numdeltas)) | 1743 numdeltas)) |
1741 | 1744 |
1745 @command('debugrevspec', | |
1746 [('', 'optimize', None, | |
1747 _('print parsed tree after optimizing (DEPRECATED)')), | |
1748 ('p', 'show-stage', [], | |
1749 _('print parsed tree at the given stage'), _('NAME')), | |
1750 ('', 'no-optimized', False, _('evaluate tree without optimization')), | |
1751 ('', 'verify-optimized', False, _('verify optimized result')), | |
1752 ], | |
1753 ('REVSPEC')) | |
1754 def debugrevspec(ui, repo, expr, **opts): | |
1755 """parse and apply a revision specification | |
1756 | |
1757 Use -p/--show-stage option to print the parsed tree at the given stages. | |
1758 Use -p all to print tree at every stage. | |
1759 | |
1760 Use --verify-optimized to compare the optimized result with the unoptimized | |
1761 one. Returns 1 if the optimized result differs. | |
1762 """ | |
1763 stages = [ | |
1764 ('parsed', lambda tree: tree), | |
1765 ('expanded', lambda tree: revset.expandaliases(ui, tree)), | |
1766 ('concatenated', revset.foldconcat), | |
1767 ('analyzed', revset.analyze), | |
1768 ('optimized', revset.optimize), | |
1769 ] | |
1770 if opts['no_optimized']: | |
1771 stages = stages[:-1] | |
1772 if opts['verify_optimized'] and opts['no_optimized']: | |
1773 raise error.Abort(_('cannot use --verify-optimized with ' | |
1774 '--no-optimized')) | |
1775 stagenames = set(n for n, f in stages) | |
1776 | |
1777 showalways = set() | |
1778 showchanged = set() | |
1779 if ui.verbose and not opts['show_stage']: | |
1780 # show parsed tree by --verbose (deprecated) | |
1781 showalways.add('parsed') | |
1782 showchanged.update(['expanded', 'concatenated']) | |
1783 if opts['optimize']: | |
1784 showalways.add('optimized') | |
1785 if opts['show_stage'] and opts['optimize']: | |
1786 raise error.Abort(_('cannot use --optimize with --show-stage')) | |
1787 if opts['show_stage'] == ['all']: | |
1788 showalways.update(stagenames) | |
1789 else: | |
1790 for n in opts['show_stage']: | |
1791 if n not in stagenames: | |
1792 raise error.Abort(_('invalid stage name: %s') % n) | |
1793 showalways.update(opts['show_stage']) | |
1794 | |
1795 treebystage = {} | |
1796 printedtree = None | |
1797 tree = revset.parse(expr, lookup=repo.__contains__) | |
1798 for n, f in stages: | |
1799 treebystage[n] = tree = f(tree) | |
1800 if n in showalways or (n in showchanged and tree != printedtree): | |
1801 if opts['show_stage'] or n != 'parsed': | |
1802 ui.write(("* %s:\n") % n) | |
1803 ui.write(revset.prettyformat(tree), "\n") | |
1804 printedtree = tree | |
1805 | |
1806 if opts['verify_optimized']: | |
1807 arevs = revset.makematcher(treebystage['analyzed'])(repo) | |
1808 brevs = revset.makematcher(treebystage['optimized'])(repo) | |
1809 if ui.verbose: | |
1810 ui.note(("* analyzed set:\n"), smartset.prettyformat(arevs), "\n") | |
1811 ui.note(("* optimized set:\n"), smartset.prettyformat(brevs), "\n") | |
1812 arevs = list(arevs) | |
1813 brevs = list(brevs) | |
1814 if arevs == brevs: | |
1815 return 0 | |
1816 ui.write(('--- analyzed\n'), label='diff.file_a') | |
1817 ui.write(('+++ optimized\n'), label='diff.file_b') | |
1818 sm = difflib.SequenceMatcher(None, arevs, brevs) | |
1819 for tag, alo, ahi, blo, bhi in sm.get_opcodes(): | |
1820 if tag in ('delete', 'replace'): | |
1821 for c in arevs[alo:ahi]: | |
1822 ui.write('-%s\n' % c, label='diff.deleted') | |
1823 if tag in ('insert', 'replace'): | |
1824 for c in brevs[blo:bhi]: | |
1825 ui.write('+%s\n' % c, label='diff.inserted') | |
1826 if tag == 'equal': | |
1827 for c in arevs[alo:ahi]: | |
1828 ui.write(' %s\n' % c) | |
1829 return 1 | |
1830 | |
1831 func = revset.makematcher(tree) | |
1832 revs = func(repo) | |
1833 if ui.verbose: | |
1834 ui.note(("* set:\n"), smartset.prettyformat(revs), "\n") | |
1835 for c in revs: | |
1836 ui.write("%s\n" % c) | |
1837 | |
1742 @command('debugupgraderepo', [ | 1838 @command('debugupgraderepo', [ |
1743 ('o', 'optimize', [], _('extra optimization to perform'), _('NAME')), | 1839 ('o', 'optimize', [], _('extra optimization to perform'), _('NAME')), |
1744 ('', 'run', False, _('performs an upgrade')), | 1840 ('', 'run', False, _('performs an upgrade')), |
1745 ]) | 1841 ]) |
1746 def debugupgraderepo(ui, repo, run=False, optimize=None): | 1842 def debugupgraderepo(ui, repo, run=False, optimize=None): |