mercurial/commands.py
changeset 30936 8de38479d60b
parent 30935 e46533c3201e
child 30937 a9aa67ba3f96
equal deleted inserted replaced
30935:e46533c3201e 30936:8de38479d60b
    17 
    17 
    18 from .i18n import _
    18 from .i18n import _
    19 from .node import (
    19 from .node import (
    20     bin,
    20     bin,
    21     hex,
    21     hex,
    22     nullhex,
       
    23     nullid,
    22     nullid,
    24     nullrev,
    23     nullrev,
    25     short,
    24     short,
    26 )
    25 )
    27 from . import (
    26 from . import (
  1861     Returns 0 on success, 1 if errors are encountered.
  1860     Returns 0 on success, 1 if errors are encountered.
  1862     """
  1861     """
  1863     with repo.wlock(False):
  1862     with repo.wlock(False):
  1864         return cmdutil.copy(ui, repo, pats, opts)
  1863         return cmdutil.copy(ui, repo, pats, opts)
  1865 
  1864 
  1866 @command('debugmergestate', [], '')
       
  1867 def debugmergestate(ui, repo, *args):
       
  1868     """print merge state
       
  1869 
       
  1870     Use --verbose to print out information about whether v1 or v2 merge state
       
  1871     was chosen."""
       
  1872     def _hashornull(h):
       
  1873         if h == nullhex:
       
  1874             return 'null'
       
  1875         else:
       
  1876             return h
       
  1877 
       
  1878     def printrecords(version):
       
  1879         ui.write(('* version %s records\n') % version)
       
  1880         if version == 1:
       
  1881             records = v1records
       
  1882         else:
       
  1883             records = v2records
       
  1884 
       
  1885         for rtype, record in records:
       
  1886             # pretty print some record types
       
  1887             if rtype == 'L':
       
  1888                 ui.write(('local: %s\n') % record)
       
  1889             elif rtype == 'O':
       
  1890                 ui.write(('other: %s\n') % record)
       
  1891             elif rtype == 'm':
       
  1892                 driver, mdstate = record.split('\0', 1)
       
  1893                 ui.write(('merge driver: %s (state "%s")\n')
       
  1894                          % (driver, mdstate))
       
  1895             elif rtype in 'FDC':
       
  1896                 r = record.split('\0')
       
  1897                 f, state, hash, lfile, afile, anode, ofile = r[0:7]
       
  1898                 if version == 1:
       
  1899                     onode = 'not stored in v1 format'
       
  1900                     flags = r[7]
       
  1901                 else:
       
  1902                     onode, flags = r[7:9]
       
  1903                 ui.write(('file: %s (record type "%s", state "%s", hash %s)\n')
       
  1904                          % (f, rtype, state, _hashornull(hash)))
       
  1905                 ui.write(('  local path: %s (flags "%s")\n') % (lfile, flags))
       
  1906                 ui.write(('  ancestor path: %s (node %s)\n')
       
  1907                          % (afile, _hashornull(anode)))
       
  1908                 ui.write(('  other path: %s (node %s)\n')
       
  1909                          % (ofile, _hashornull(onode)))
       
  1910             elif rtype == 'f':
       
  1911                 filename, rawextras = record.split('\0', 1)
       
  1912                 extras = rawextras.split('\0')
       
  1913                 i = 0
       
  1914                 extrastrings = []
       
  1915                 while i < len(extras):
       
  1916                     extrastrings.append('%s = %s' % (extras[i], extras[i + 1]))
       
  1917                     i += 2
       
  1918 
       
  1919                 ui.write(('file extras: %s (%s)\n')
       
  1920                          % (filename, ', '.join(extrastrings)))
       
  1921             elif rtype == 'l':
       
  1922                 labels = record.split('\0', 2)
       
  1923                 labels = [l for l in labels if len(l) > 0]
       
  1924                 ui.write(('labels:\n'))
       
  1925                 ui.write(('  local: %s\n' % labels[0]))
       
  1926                 ui.write(('  other: %s\n' % labels[1]))
       
  1927                 if len(labels) > 2:
       
  1928                     ui.write(('  base:  %s\n' % labels[2]))
       
  1929             else:
       
  1930                 ui.write(('unrecognized entry: %s\t%s\n')
       
  1931                          % (rtype, record.replace('\0', '\t')))
       
  1932 
       
  1933     # Avoid mergestate.read() since it may raise an exception for unsupported
       
  1934     # merge state records. We shouldn't be doing this, but this is OK since this
       
  1935     # command is pretty low-level.
       
  1936     ms = mergemod.mergestate(repo)
       
  1937 
       
  1938     # sort so that reasonable information is on top
       
  1939     v1records = ms._readrecordsv1()
       
  1940     v2records = ms._readrecordsv2()
       
  1941     order = 'LOml'
       
  1942     def key(r):
       
  1943         idx = order.find(r[0])
       
  1944         if idx == -1:
       
  1945             return (1, r[1])
       
  1946         else:
       
  1947             return (0, idx)
       
  1948     v1records.sort(key=key)
       
  1949     v2records.sort(key=key)
       
  1950 
       
  1951     if not v1records and not v2records:
       
  1952         ui.write(('no merge state found\n'))
       
  1953     elif not v2records:
       
  1954         ui.note(('no version 2 merge state\n'))
       
  1955         printrecords(1)
       
  1956     elif ms._v1v2match(v1records, v2records):
       
  1957         ui.note(('v1 and v2 states match: using v2\n'))
       
  1958         printrecords(2)
       
  1959     else:
       
  1960         ui.note(('v1 and v2 states mismatch: using v1\n'))
       
  1961         printrecords(1)
       
  1962         if ui.verbose:
       
  1963             printrecords(2)
       
  1964 
       
  1965 @command('debugnamecomplete', [], _('NAME...'))
  1865 @command('debugnamecomplete', [], _('NAME...'))
  1966 def debugnamecomplete(ui, repo, *args):
  1866 def debugnamecomplete(ui, repo, *args):
  1967     '''complete "names" - tags, open branch names, bookmark names'''
  1867     '''complete "names" - tags, open branch names, bookmark names'''
  1968 
  1868 
  1969     names = set()
  1869     names = set()