[PATCH 3 of 4 stream clone bundles] commands: support creating stream clone bundles

Gregory Szorc gregory.szorc at gmail.com
Thu Oct 15 15:44:12 CDT 2015


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1444941763 25200
#      Thu Oct 15 13:42:43 2015 -0700
# Node ID 9968b26ad6ece6b86561f958f28926b078cc19b0
# Parent  e86a5c3ab27873461de51b0f9f36100fd8f1531a
commands: support creating stream clone bundles

Now that we have support for recognizing the streaming clone bundle
type, add a debug command for creating them.

I decided to create a new debug command instead of adding support to `hg
bundle` because stream clone bundles are not exactly used the same way
as normal bundle files and I don't want to commit to supporting them
through the official `hg bundle` command forever. A debug command,
however, can be changed without as much concern for backwards
compatibility.

As part of this, `hg bundle` will explicitly reject requests to produce
stream bundles.

This command will be required by server operators using stream clone
bundles with the clone bundles feature.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -22,8 +22,9 @@ import dagparser, context, simplemerge, 
 import random, operator
 import setdiscovery, treediscovery, dagutil, pvec, localrepo, destutil
 import phases, obsolete, exchange, bundle2, repair, lock as lockmod
 import ui as uimod
+import streamclone
 
 table = {}
 
 command = cmdutil.command(table)
@@ -1249,8 +1250,13 @@ def bundle(ui, repo, fname, dest=None, *
         raise error.Abort(str(e),
                           hint=_('see "hg help bundle" for supported '
                                  'values for --type'))
 
+    # Packed bundles are a pseudo bundle format for now.
+    if cgversion == 's1':
+        raise error.Abort(_('packed bundles cannot be produced by "hg bundle"'),
+                          hint=_('use "hg debugcreatestreamclonebundle"'))
+
     if opts.get('all'):
         base = ['null']
     else:
         base = scmutil.revrange(repo, opts.get('base'))
@@ -1959,8 +1965,18 @@ def _debugbundle2(ui, gen, **opts):
                 node = chunkdata['node']
                 ui.write("    %s\n" % hex(node))
                 chain = node
 
+ at command('debugcreatestreamclonebundle', [], 'FILE')
+def debugcreatestreamclonebundle(ui, repo, fname):
+    """create a stream clone bundle file
+
+    Stream bundles are special bundles that are essentially archives of
+    revlog files. They are commonly used for cloning very quickly.
+    """
+    gen = streamclone.generatebundlev1(repo)
+    changegroup.writechunks(ui, gen, fname)
+
 @command('debugcheckstate', [], '')
 def debugcheckstate(ui, repo):
     """validate the correctness of the current dirstate"""
     parent1, parent2 = repo.dirstate.parents()
diff --git a/tests/test-bundle.t b/tests/test-bundle.t
--- a/tests/test-bundle.t
+++ b/tests/test-bundle.t
@@ -249,8 +249,27 @@ Pull full.hg into empty again (using -R;
   added 9 changesets with 7 changes to 4 files (+1 heads)
   changegroup hook: HG_NODE=f9ee2f85a263049e9ae6d37a0e67e96194ffb735 HG_SOURCE=pull HG_TXNID=TXN:* HG_URL=bundle:empty+full.hg (glob)
   (run 'hg heads' to see heads, 'hg merge' to merge)
 
+Cannot produce streaming clone bundles with "hg bundle"
+
+  $ hg -R test bundle -t packed1 packed.hg
+  abort: packed bundles cannot be produced by "hg bundle"
+  (use "hg debugcreatestreamclonebundle")
+  [255]
+
+packed1 is produced properly
+
+  $ hg -R test debugcreatestreamclonebundle packed.hg
+  writing 2608 bytes for 6 files
+
+  $ f -B 64 --size --hexdump packed.hg
+  packed.hg: size=2758
+  0000: 48 47 53 31 55 4e 00 00 00 00 00 00 00 06 00 00 |HGS1UN..........|
+  0010: 00 00 00 00 0a 30 00 09 72 65 76 6c 6f 67 76 31 |.....0..revlogv1|
+  0020: 00 64 61 74 61 2f 61 64 69 66 66 65 72 65 6e 74 |.data/adifferent|
+  0030: 66 69 6c 65 2e 69 00 31 33 39 0a 00 01 00 01 00 |file.i.139......|
+
 Create partial clones
 
   $ rm -r empty
   $ hg init empty
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -74,8 +74,9 @@ Show debug commands if there are no othe
   debugcheckstate
   debugcommands
   debugcomplete
   debugconfig
+  debugcreatestreamclonebundle
   debugdag
   debugdata
   debugdate
   debugdirstate
@@ -235,8 +236,9 @@ Show all commands + options
   debugbundle: all
   debugcheckstate: 
   debugcommands: 
   debugcomplete: options
+  debugcreatestreamclonebundle: 
   debugdag: tags, branches, dots, spaces
   debugdata: changelog, manifest, dir
   debugdate: extended
   debugdirstate: nodates, datesort
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -790,8 +790,10 @@ Test list of internal help commands
    debugcommands
                  list all available commands and options
    debugcomplete
                  returns the completion list associated with the given command
+   debugcreatestreamclonebundle
+                 create a stream clone bundle file
    debugdag      format the changelog or an index DAG as a concise textual
                  description
    debugdata     dump the contents of a data file revision
    debugdate     parse and display a date
@@ -1063,12 +1065,13 @@ Test keyword search help
    urls       URL Paths
   
   Commands:
   
-   bookmarks create a new bookmark or list existing bookmarks
-   clone     make a copy of an existing repository
-   paths     show aliases for remote repositories
-   update    update working directory (or switch revisions)
+   bookmarks                    create a new bookmark or list existing bookmarks
+   clone                        make a copy of an existing repository
+   debugcreatestreamclonebundle create a stream clone bundle file
+   paths                        show aliases for remote repositories
+   update                       update working directory (or switch revisions)
   
   Extensions:
   
    clonebundles server side extension to advertise pre-generated bundles to seed


More information about the Mercurial-devel mailing list