mercurial/debugcommands.py
changeset 30936 8de38479d60b
parent 30935 e46533c3201e
child 30937 a9aa67ba3f96
equal deleted inserted replaced
30935:e46533c3201e 30936:8de38479d60b
    15 
    15 
    16 from .i18n import _
    16 from .i18n import _
    17 from .node import (
    17 from .node import (
    18     bin,
    18     bin,
    19     hex,
    19     hex,
       
    20     nullhex,
    20     nullid,
    21     nullid,
    21     short,
    22     short,
    22 )
    23 )
    23 from . import (
    24 from . import (
    24     bundle2,
    25     bundle2,
    34     extensions,
    35     extensions,
    35     fileset,
    36     fileset,
    36     hg,
    37     hg,
    37     localrepo,
    38     localrepo,
    38     lock as lockmod,
    39     lock as lockmod,
       
    40     merge as mergemod,
    39     policy,
    41     policy,
    40     pycompat,
    42     pycompat,
    41     repair,
    43     repair,
    42     revlog,
    44     revlog,
    43     scmutil,
    45     scmutil,
  1039 @command('debuglabelcomplete', [], _('LABEL...'))
  1041 @command('debuglabelcomplete', [], _('LABEL...'))
  1040 def debuglabelcomplete(ui, repo, *args):
  1042 def debuglabelcomplete(ui, repo, *args):
  1041     '''backwards compatibility with old bash completion scripts (DEPRECATED)'''
  1043     '''backwards compatibility with old bash completion scripts (DEPRECATED)'''
  1042     commands.debugnamecomplete(ui, repo, *args)
  1044     commands.debugnamecomplete(ui, repo, *args)
  1043 
  1045 
       
  1046 @command('debugmergestate', [], '')
       
  1047 def debugmergestate(ui, repo, *args):
       
  1048     """print merge state
       
  1049 
       
  1050     Use --verbose to print out information about whether v1 or v2 merge state
       
  1051     was chosen."""
       
  1052     def _hashornull(h):
       
  1053         if h == nullhex:
       
  1054             return 'null'
       
  1055         else:
       
  1056             return h
       
  1057 
       
  1058     def printrecords(version):
       
  1059         ui.write(('* version %s records\n') % version)
       
  1060         if version == 1:
       
  1061             records = v1records
       
  1062         else:
       
  1063             records = v2records
       
  1064 
       
  1065         for rtype, record in records:
       
  1066             # pretty print some record types
       
  1067             if rtype == 'L':
       
  1068                 ui.write(('local: %s\n') % record)
       
  1069             elif rtype == 'O':
       
  1070                 ui.write(('other: %s\n') % record)
       
  1071             elif rtype == 'm':
       
  1072                 driver, mdstate = record.split('\0', 1)
       
  1073                 ui.write(('merge driver: %s (state "%s")\n')
       
  1074                          % (driver, mdstate))
       
  1075             elif rtype in 'FDC':
       
  1076                 r = record.split('\0')
       
  1077                 f, state, hash, lfile, afile, anode, ofile = r[0:7]
       
  1078                 if version == 1:
       
  1079                     onode = 'not stored in v1 format'
       
  1080                     flags = r[7]
       
  1081                 else:
       
  1082                     onode, flags = r[7:9]
       
  1083                 ui.write(('file: %s (record type "%s", state "%s", hash %s)\n')
       
  1084                          % (f, rtype, state, _hashornull(hash)))
       
  1085                 ui.write(('  local path: %s (flags "%s")\n') % (lfile, flags))
       
  1086                 ui.write(('  ancestor path: %s (node %s)\n')
       
  1087                          % (afile, _hashornull(anode)))
       
  1088                 ui.write(('  other path: %s (node %s)\n')
       
  1089                          % (ofile, _hashornull(onode)))
       
  1090             elif rtype == 'f':
       
  1091                 filename, rawextras = record.split('\0', 1)
       
  1092                 extras = rawextras.split('\0')
       
  1093                 i = 0
       
  1094                 extrastrings = []
       
  1095                 while i < len(extras):
       
  1096                     extrastrings.append('%s = %s' % (extras[i], extras[i + 1]))
       
  1097                     i += 2
       
  1098 
       
  1099                 ui.write(('file extras: %s (%s)\n')
       
  1100                          % (filename, ', '.join(extrastrings)))
       
  1101             elif rtype == 'l':
       
  1102                 labels = record.split('\0', 2)
       
  1103                 labels = [l for l in labels if len(l) > 0]
       
  1104                 ui.write(('labels:\n'))
       
  1105                 ui.write(('  local: %s\n' % labels[0]))
       
  1106                 ui.write(('  other: %s\n' % labels[1]))
       
  1107                 if len(labels) > 2:
       
  1108                     ui.write(('  base:  %s\n' % labels[2]))
       
  1109             else:
       
  1110                 ui.write(('unrecognized entry: %s\t%s\n')
       
  1111                          % (rtype, record.replace('\0', '\t')))
       
  1112 
       
  1113     # Avoid mergestate.read() since it may raise an exception for unsupported
       
  1114     # merge state records. We shouldn't be doing this, but this is OK since this
       
  1115     # command is pretty low-level.
       
  1116     ms = mergemod.mergestate(repo)
       
  1117 
       
  1118     # sort so that reasonable information is on top
       
  1119     v1records = ms._readrecordsv1()
       
  1120     v2records = ms._readrecordsv2()
       
  1121     order = 'LOml'
       
  1122     def key(r):
       
  1123         idx = order.find(r[0])
       
  1124         if idx == -1:
       
  1125             return (1, r[1])
       
  1126         else:
       
  1127             return (0, idx)
       
  1128     v1records.sort(key=key)
       
  1129     v2records.sort(key=key)
       
  1130 
       
  1131     if not v1records and not v2records:
       
  1132         ui.write(('no merge state found\n'))
       
  1133     elif not v2records:
       
  1134         ui.note(('no version 2 merge state\n'))
       
  1135         printrecords(1)
       
  1136     elif ms._v1v2match(v1records, v2records):
       
  1137         ui.note(('v1 and v2 states match: using v2\n'))
       
  1138         printrecords(2)
       
  1139     else:
       
  1140         ui.note(('v1 and v2 states mismatch: using v1\n'))
       
  1141         printrecords(1)
       
  1142         if ui.verbose:
       
  1143             printrecords(2)
       
  1144 
  1044 @command('debugupgraderepo', [
  1145 @command('debugupgraderepo', [
  1045     ('o', 'optimize', [], _('extra optimization to perform'), _('NAME')),
  1146     ('o', 'optimize', [], _('extra optimization to perform'), _('NAME')),
  1046     ('', 'run', False, _('performs an upgrade')),
  1147     ('', 'run', False, _('performs an upgrade')),
  1047 ])
  1148 ])
  1048 def debugupgraderepo(ui, repo, run=False, optimize=None):
  1149 def debugupgraderepo(ui, repo, run=False, optimize=None):