[PATCH 1 of 2] commands.debugbundle: Bundle2 support

Eric Sumner ericsumner at fb.com
Fri Jan 16 20:20:56 UTC 2015


# HG changeset patch
# User Eric Sumner <ericsumner at fb.com>
# Date 1421364926 28800
#      Thu Jan 15 15:35:26 2015 -0800
# Node ID e07587a186a859fdb065b9475afd0470e2ae4508
# Parent  049a9e3a078d7c988cb12ed456aad6ec2779ea69
commands.debugbundle: Bundle2 support

This enables debugbundle to print supporting info for bundle2 files.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -21,7 +21,7 @@
 import dagparser, context, simplemerge, graphmod, copies
 import random
 import setdiscovery, treediscovery, dagutil, pvec, localrepo
-import phases, obsolete, exchange
+import phases, obsolete, exchange, bundle2
 import ui as uimod
 
 table = {}
@@ -1817,6 +1817,8 @@
     f = hg.openpath(ui, bundlepath)
     try:
         gen = exchange.readbundle(ui, f, bundlepath)
+        if isinstance(gen, bundle2.unbundle20):
+            return _debugbundle2(ui, gen, all=all, **opts)
         if all:
             ui.write(("format: id, p1, p2, cset, delta base, len(delta)\n"))
 
@@ -1849,6 +1851,8 @@
                 fname = chunkdata['filename']
                 showchunks(fname)
         else:
+            if isinstance(gen, bundle2.unbundle20):
+                raise util.Abort(_('Use debugbundle2 for this file'))
             chunkdata = gen.changelogheader()
             chain = None
             while True:
@@ -1861,6 +1865,26 @@
     finally:
         f.close()
 
+def _debugbundle2(ui, gen, **opts):
+    """lists the contents of a bundle2"""
+    if not isinstance(gen, bundle2.unbundle20):
+        raise util.Abort(_('Not a bundle2 file'))
+    ui.write('Stream params: %s\n' % repr(gen.params))
+    for part in gen.iterparts():
+        ui.write('%s -- %r\n' % (part.type, repr(part.params)))
+        if part.type == 'b2x:changegroup':
+            version = part.params.get('version', '01')
+            cg = changegroup.packermap[version][1](part, 'UN')
+            chunkdata = cg.changelogheader()
+            chain = None
+            while True:
+                chunkdata = cg.deltachunk(chain)
+                if not chunkdata:
+                    break
+                node = chunkdata['node']
+                ui.write("    %s\n" % hex(node))
+                chain = node
+
 @command('debugcheckstate', [], '')
 def debugcheckstate(ui, repo):
     """validate the correctness of the current dirstate"""
diff --git a/tests/test-bundle2-format.t b/tests/test-bundle2-format.t
--- a/tests/test-bundle2-format.t
+++ b/tests/test-bundle2-format.t
@@ -755,6 +755,13 @@
   \x87\xcd\xc9n\x8e\xaa\xb6\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02H (esc)
   \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 (no-eol) (esc)
 
+  $ hg debugbundle ../rev.hg2
+  Stream params: {}
+  b2x:changegroup -- '{}'
+      32af7686d403cf45b5d95f2d70cebea587ac806a
+      9520eea781bcca16c1e15acc0ba14335a0e8e5ba
+      eea13746799a9e0bfd88f29d3c2e9dc9389f524f
+      02de42196ebee42ef284b6780a87cdc96e8eaab6
   $ hg unbundle2 < ../rev.hg2
   adding changesets
   adding manifests


More information about the Mercurial-devel mailing list