mercurial/commands.py
changeset 30501 a87e469201f9
parent 30491 13251523b20c
child 30502 6da030496667
equal deleted inserted replaced
30500:fc0cfe6c87d7 30501:a87e469201f9
  1865     Returns 0 on success, 1 if errors are encountered.
  1865     Returns 0 on success, 1 if errors are encountered.
  1866     """
  1866     """
  1867     with repo.wlock(False):
  1867     with repo.wlock(False):
  1868         return cmdutil.copy(ui, repo, pats, opts)
  1868         return cmdutil.copy(ui, repo, pats, opts)
  1869 
  1869 
  1870 @command('debugbundle',
       
  1871         [('a', 'all', None, _('show all details')),
       
  1872          ('', 'spec', None, _('print the bundlespec of the bundle'))],
       
  1873         _('FILE'),
       
  1874         norepo=True)
       
  1875 def debugbundle(ui, bundlepath, all=None, spec=None, **opts):
       
  1876     """lists the contents of a bundle"""
       
  1877     with hg.openpath(ui, bundlepath) as f:
       
  1878         if spec:
       
  1879             spec = exchange.getbundlespec(ui, f)
       
  1880             ui.write('%s\n' % spec)
       
  1881             return
       
  1882 
       
  1883         gen = exchange.readbundle(ui, f, bundlepath)
       
  1884         if isinstance(gen, bundle2.unbundle20):
       
  1885             return _debugbundle2(ui, gen, all=all, **opts)
       
  1886         _debugchangegroup(ui, gen, all=all, **opts)
       
  1887 
       
  1888 def _debugchangegroup(ui, gen, all=None, indent=0, **opts):
       
  1889     indent_string = ' ' * indent
       
  1890     if all:
       
  1891         ui.write(("%sformat: id, p1, p2, cset, delta base, len(delta)\n")
       
  1892                  % indent_string)
       
  1893 
       
  1894         def showchunks(named):
       
  1895             ui.write("\n%s%s\n" % (indent_string, named))
       
  1896             chain = None
       
  1897             for chunkdata in iter(lambda: gen.deltachunk(chain), {}):
       
  1898                 node = chunkdata['node']
       
  1899                 p1 = chunkdata['p1']
       
  1900                 p2 = chunkdata['p2']
       
  1901                 cs = chunkdata['cs']
       
  1902                 deltabase = chunkdata['deltabase']
       
  1903                 delta = chunkdata['delta']
       
  1904                 ui.write("%s%s %s %s %s %s %s\n" %
       
  1905                          (indent_string, hex(node), hex(p1), hex(p2),
       
  1906                           hex(cs), hex(deltabase), len(delta)))
       
  1907                 chain = node
       
  1908 
       
  1909         chunkdata = gen.changelogheader()
       
  1910         showchunks("changelog")
       
  1911         chunkdata = gen.manifestheader()
       
  1912         showchunks("manifest")
       
  1913         for chunkdata in iter(gen.filelogheader, {}):
       
  1914             fname = chunkdata['filename']
       
  1915             showchunks(fname)
       
  1916     else:
       
  1917         if isinstance(gen, bundle2.unbundle20):
       
  1918             raise error.Abort(_('use debugbundle2 for this file'))
       
  1919         chunkdata = gen.changelogheader()
       
  1920         chain = None
       
  1921         for chunkdata in iter(lambda: gen.deltachunk(chain), {}):
       
  1922             node = chunkdata['node']
       
  1923             ui.write("%s%s\n" % (indent_string, hex(node)))
       
  1924             chain = node
       
  1925 
       
  1926 def _debugbundle2(ui, gen, all=None, **opts):
       
  1927     """lists the contents of a bundle2"""
       
  1928     if not isinstance(gen, bundle2.unbundle20):
       
  1929         raise error.Abort(_('not a bundle2 file'))
       
  1930     ui.write(('Stream params: %s\n' % repr(gen.params)))
       
  1931     for part in gen.iterparts():
       
  1932         ui.write('%s -- %r\n' % (part.type, repr(part.params)))
       
  1933         if part.type == 'changegroup':
       
  1934             version = part.params.get('version', '01')
       
  1935             cg = changegroup.getunbundler(version, part, 'UN')
       
  1936             _debugchangegroup(ui, cg, all=all, indent=4, **opts)
       
  1937 
       
  1938 @command('debugcreatestreamclonebundle', [], 'FILE')
  1870 @command('debugcreatestreamclonebundle', [], 'FILE')
  1939 def debugcreatestreamclonebundle(ui, repo, fname):
  1871 def debugcreatestreamclonebundle(ui, repo, fname):
  1940     """create a stream clone bundle file
  1872     """create a stream clone bundle file
  1941 
  1873 
  1942     Stream bundles are special bundles that are essentially archives of
  1874     Stream bundles are special bundles that are essentially archives of