##// END OF EJS Templates
debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David -
r30952:85c3c879 default
parent child Browse files
Show More
@@ -49,7 +49,6 from . import (
49 revset,
49 revset,
50 scmutil,
50 scmutil,
51 server,
51 server,
52 smartset,
53 sshserver,
52 sshserver,
54 streamclone,
53 streamclone,
55 templatekw,
54 templatekw,
@@ -1856,99 +1855,6 def copy(ui, repo, *pats, **opts):
1856 with repo.wlock(False):
1855 with repo.wlock(False):
1857 return cmdutil.copy(ui, repo, pats, opts)
1856 return cmdutil.copy(ui, repo, pats, opts)
1858
1857
1859 @command('debugrevspec',
1860 [('', 'optimize', None,
1861 _('print parsed tree after optimizing (DEPRECATED)')),
1862 ('p', 'show-stage', [],
1863 _('print parsed tree at the given stage'), _('NAME')),
1864 ('', 'no-optimized', False, _('evaluate tree without optimization')),
1865 ('', 'verify-optimized', False, _('verify optimized result')),
1866 ],
1867 ('REVSPEC'))
1868 def debugrevspec(ui, repo, expr, **opts):
1869 """parse and apply a revision specification
1870
1871 Use -p/--show-stage option to print the parsed tree at the given stages.
1872 Use -p all to print tree at every stage.
1873
1874 Use --verify-optimized to compare the optimized result with the unoptimized
1875 one. Returns 1 if the optimized result differs.
1876 """
1877 stages = [
1878 ('parsed', lambda tree: tree),
1879 ('expanded', lambda tree: revset.expandaliases(ui, tree)),
1880 ('concatenated', revset.foldconcat),
1881 ('analyzed', revset.analyze),
1882 ('optimized', revset.optimize),
1883 ]
1884 if opts['no_optimized']:
1885 stages = stages[:-1]
1886 if opts['verify_optimized'] and opts['no_optimized']:
1887 raise error.Abort(_('cannot use --verify-optimized with '
1888 '--no-optimized'))
1889 stagenames = set(n for n, f in stages)
1890
1891 showalways = set()
1892 showchanged = set()
1893 if ui.verbose and not opts['show_stage']:
1894 # show parsed tree by --verbose (deprecated)
1895 showalways.add('parsed')
1896 showchanged.update(['expanded', 'concatenated'])
1897 if opts['optimize']:
1898 showalways.add('optimized')
1899 if opts['show_stage'] and opts['optimize']:
1900 raise error.Abort(_('cannot use --optimize with --show-stage'))
1901 if opts['show_stage'] == ['all']:
1902 showalways.update(stagenames)
1903 else:
1904 for n in opts['show_stage']:
1905 if n not in stagenames:
1906 raise error.Abort(_('invalid stage name: %s') % n)
1907 showalways.update(opts['show_stage'])
1908
1909 treebystage = {}
1910 printedtree = None
1911 tree = revset.parse(expr, lookup=repo.__contains__)
1912 for n, f in stages:
1913 treebystage[n] = tree = f(tree)
1914 if n in showalways or (n in showchanged and tree != printedtree):
1915 if opts['show_stage'] or n != 'parsed':
1916 ui.write(("* %s:\n") % n)
1917 ui.write(revset.prettyformat(tree), "\n")
1918 printedtree = tree
1919
1920 if opts['verify_optimized']:
1921 arevs = revset.makematcher(treebystage['analyzed'])(repo)
1922 brevs = revset.makematcher(treebystage['optimized'])(repo)
1923 if ui.verbose:
1924 ui.note(("* analyzed set:\n"), smartset.prettyformat(arevs), "\n")
1925 ui.note(("* optimized set:\n"), smartset.prettyformat(brevs), "\n")
1926 arevs = list(arevs)
1927 brevs = list(brevs)
1928 if arevs == brevs:
1929 return 0
1930 ui.write(('--- analyzed\n'), label='diff.file_a')
1931 ui.write(('+++ optimized\n'), label='diff.file_b')
1932 sm = difflib.SequenceMatcher(None, arevs, brevs)
1933 for tag, alo, ahi, blo, bhi in sm.get_opcodes():
1934 if tag in ('delete', 'replace'):
1935 for c in arevs[alo:ahi]:
1936 ui.write('-%s\n' % c, label='diff.deleted')
1937 if tag in ('insert', 'replace'):
1938 for c in brevs[blo:bhi]:
1939 ui.write('+%s\n' % c, label='diff.inserted')
1940 if tag == 'equal':
1941 for c in arevs[alo:ahi]:
1942 ui.write(' %s\n' % c)
1943 return 1
1944
1945 func = revset.makematcher(tree)
1946 revs = func(repo)
1947 if ui.verbose:
1948 ui.note(("* set:\n"), smartset.prettyformat(revs), "\n")
1949 for c in revs:
1950 ui.write("%s\n" % c)
1951
1952 @command('debugsetparents', [], _('REV1 [REV2]'))
1858 @command('debugsetparents', [], _('REV1 [REV2]'))
1953 def debugsetparents(ui, repo, rev1, rev2=None):
1859 def debugsetparents(ui, repo, rev1, rev2=None):
1954 """manually set the parents of the current working directory
1860 """manually set the parents of the current working directory
@@ -7,6 +7,7
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
@@ -49,9 +50,11 from . import (
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,
@@ -1739,6 +1742,99 def debugrevlog(ui, repo, file_=None, **
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')),
General Comments 0
You need to be logged in to leave comments. Login now