mercurial/debugcommands.py
changeset 30501 a87e469201f9
parent 30402 945f8229b30d
child 30502 6da030496667
equal deleted inserted replaced
30500:fc0cfe6c87d7 30501:a87e469201f9
    12 from .i18n import _
    12 from .i18n import _
    13 from .node import (
    13 from .node import (
    14     hex,
    14     hex,
    15 )
    15 )
    16 from . import (
    16 from . import (
       
    17     bundle2,
       
    18     changegroup,
    17     cmdutil,
    19     cmdutil,
    18     commands,
    20     commands,
    19     context,
    21     context,
    20     dagparser,
    22     dagparser,
    21     error,
    23     error,
       
    24     exchange,
       
    25     hg,
    22     lock as lockmod,
    26     lock as lockmod,
    23     revlog,
    27     revlog,
    24     scmutil,
    28     scmutil,
    25     simplemerge,
    29     simplemerge,
    26 )
    30 )
   199         if tags:
   203         if tags:
   200             repo.vfs.write("localtags", "".join(tags))
   204             repo.vfs.write("localtags", "".join(tags))
   201     finally:
   205     finally:
   202         ui.progress(_('building'), None)
   206         ui.progress(_('building'), None)
   203         release(tr, lock, wlock)
   207         release(tr, lock, wlock)
       
   208 
       
   209 @command('debugbundle',
       
   210         [('a', 'all', None, _('show all details')),
       
   211          ('', 'spec', None, _('print the bundlespec of the bundle'))],
       
   212         _('FILE'),
       
   213         norepo=True)
       
   214 def debugbundle(ui, bundlepath, all=None, spec=None, **opts):
       
   215     """lists the contents of a bundle"""
       
   216     with hg.openpath(ui, bundlepath) as f:
       
   217         if spec:
       
   218             spec = exchange.getbundlespec(ui, f)
       
   219             ui.write('%s\n' % spec)
       
   220             return
       
   221 
       
   222         gen = exchange.readbundle(ui, f, bundlepath)
       
   223         if isinstance(gen, bundle2.unbundle20):
       
   224             return _debugbundle2(ui, gen, all=all, **opts)
       
   225         _debugchangegroup(ui, gen, all=all, **opts)
       
   226 
       
   227 def _debugchangegroup(ui, gen, all=None, indent=0, **opts):
       
   228     indent_string = ' ' * indent
       
   229     if all:
       
   230         ui.write(("%sformat: id, p1, p2, cset, delta base, len(delta)\n")
       
   231                  % indent_string)
       
   232 
       
   233         def showchunks(named):
       
   234             ui.write("\n%s%s\n" % (indent_string, named))
       
   235             chain = None
       
   236             for chunkdata in iter(lambda: gen.deltachunk(chain), {}):
       
   237                 node = chunkdata['node']
       
   238                 p1 = chunkdata['p1']
       
   239                 p2 = chunkdata['p2']
       
   240                 cs = chunkdata['cs']
       
   241                 deltabase = chunkdata['deltabase']
       
   242                 delta = chunkdata['delta']
       
   243                 ui.write("%s%s %s %s %s %s %s\n" %
       
   244                          (indent_string, hex(node), hex(p1), hex(p2),
       
   245                           hex(cs), hex(deltabase), len(delta)))
       
   246                 chain = node
       
   247 
       
   248         chunkdata = gen.changelogheader()
       
   249         showchunks("changelog")
       
   250         chunkdata = gen.manifestheader()
       
   251         showchunks("manifest")
       
   252         for chunkdata in iter(gen.filelogheader, {}):
       
   253             fname = chunkdata['filename']
       
   254             showchunks(fname)
       
   255     else:
       
   256         if isinstance(gen, bundle2.unbundle20):
       
   257             raise error.Abort(_('use debugbundle2 for this file'))
       
   258         chunkdata = gen.changelogheader()
       
   259         chain = None
       
   260         for chunkdata in iter(lambda: gen.deltachunk(chain), {}):
       
   261             node = chunkdata['node']
       
   262             ui.write("%s%s\n" % (indent_string, hex(node)))
       
   263             chain = node
       
   264 
       
   265 def _debugbundle2(ui, gen, all=None, **opts):
       
   266     """lists the contents of a bundle2"""
       
   267     if not isinstance(gen, bundle2.unbundle20):
       
   268         raise error.Abort(_('not a bundle2 file'))
       
   269     ui.write(('Stream params: %s\n' % repr(gen.params)))
       
   270     for part in gen.iterparts():
       
   271         ui.write('%s -- %r\n' % (part.type, repr(part.params)))
       
   272         if part.type == 'changegroup':
       
   273             version = part.params.get('version', '01')
       
   274             cg = changegroup.getunbundler(version, part, 'UN')
       
   275             _debugchangegroup(ui, cg, all=all, indent=4, **opts)