mercurial/debugcommands.py
changeset 30526 9c10905f4b48
parent 30525 86ebd2f61c31
child 30527 243ecbd4f5c9
--- a/mercurial/debugcommands.py	Wed Aug 17 20:58:16 2016 -0700
+++ b/mercurial/debugcommands.py	Thu Nov 10 09:44:47 2016 -0800
@@ -13,6 +13,7 @@
 
 from .i18n import _
 from .node import (
+    bin,
     hex,
     short,
 )
@@ -597,3 +598,37 @@
     ui.write(('case-sensitive: %s\n') % (util.fscasesensitive('.debugfsinfo')
                                 and 'yes' or 'no'))
     os.unlink('.debugfsinfo')
+
+@command('debuggetbundle',
+    [('H', 'head', [], _('id of head node'), _('ID')),
+    ('C', 'common', [], _('id of common node'), _('ID')),
+    ('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE'))],
+    _('REPO FILE [-H|-C ID]...'),
+    norepo=True)
+def debuggetbundle(ui, repopath, bundlepath, head=None, common=None, **opts):
+    """retrieves a bundle from a repo
+
+    Every ID must be a full-length hex node id string. Saves the bundle to the
+    given file.
+    """
+    repo = hg.peer(ui, opts, repopath)
+    if not repo.capable('getbundle'):
+        raise error.Abort("getbundle() not supported by target repository")
+    args = {}
+    if common:
+        args['common'] = [bin(s) for s in common]
+    if head:
+        args['heads'] = [bin(s) for s in head]
+    # TODO: get desired bundlecaps from command line.
+    args['bundlecaps'] = None
+    bundle = repo.getbundle('debug', **args)
+
+    bundletype = opts.get('type', 'bzip2').lower()
+    btypes = {'none': 'HG10UN',
+              'bzip2': 'HG10BZ',
+              'gzip': 'HG10GZ',
+              'bundle2': 'HG20'}
+    bundletype = btypes.get(bundletype)
+    if bundletype not in bundle2.bundletypes:
+        raise error.Abort(_('unknown bundle type specified with --type'))
+    bundle2.writebundle(ui, bundle, bundlepath, bundletype)