1854 Returns 0 on success, 1 if errors are encountered. |
1853 Returns 0 on success, 1 if errors are encountered. |
1855 """ |
1854 """ |
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 |
1955 |
1861 |
1956 This is useful for writing repository conversion tools, but should |
1862 This is useful for writing repository conversion tools, but should |