Patchwork [3,of,4,RFC,stream,clone,bundles] commands.bundle: support creating stream clone bundles

login
register
mail settings
Submitter Gregory Szorc
Date Oct. 14, 2015, 10:34 p.m.
Message ID <e577b42c94d917eb3fbb.1444862042@gps-mbp.local>
Download mbox | patch
Permalink /patch/11078/
State Deferred
Headers show

Comments

Gregory Szorc - Oct. 14, 2015, 10:34 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1444860739 25200
#      Wed Oct 14 15:12:19 2015 -0700
# Node ID e577b42c94d917eb3fbbe866bf66e455a251bb1b
# Parent  4782148b9f8172653e3438e15c3d63771f5f395c
commands.bundle: support creating stream clone bundles

Now that we have support for recognizing the streaming clone bundle
type, add support to `hg bundle` for creating them.

I think `hg bundle` is the logical command to create bundles. However,
one can make the argument that what `hg bundle` does and what streaming
clones do is such a vastly different use case that they warrant separate
commands. The target audience for producing stream clone bundles is
probably very small. So I could understand if people feel this
functionality should be in a debug* command for now.

Patch

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)
@@ -1224,9 +1225,9 @@  def bundle(ui, repo, fname, dest=None, *
     You can change bundle format with the -t/--type option. You can
     specify a compression, a bundle version or both using a dash
     (comp-version). The available compression methods are: none, bzip2,
     and gzip (by default, bundles are compressed using bzip2). The
-    available format are: v1, v2 (default to most suitable).
+    available format are: v1, v2 (default to most suitable), and packed1.
 
     The bundle file can then be transferred using conventional means
     and applied to another repository with the unbundle or pull
     command. This is useful when direct push and pull are not
@@ -1249,8 +1250,24 @@  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 special case that doesn't need to go through
+    # the complicated changegroup flow below.
+    if cgversion == 's1':
+        if opts.get('rev'):
+            raise error.Abort(_('--rev cannot be used with packed bundles'))
+        if opts.get('base'):
+            raise error.Abort(_('--base cannot be used with packed bundles'))
+
+        if bcompression is not None:
+            raise error.Abort(_('packed bundles do not yet support '
+                                'compression'))
+
+        gen = streamclone.generatebundlev1(repo)
+        changegroup.writechunks(ui, gen, fname)
+        return
+
     if opts.get('all'):
         base = ['null']
     else:
         base = scmutil.revrange(repo, opts.get('base'))
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,36 @@  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)
 
+packed1 rejects --rev and --base
+
+  $ hg -R test bundle -t packed1 --rev 0 packed.hg
+  abort: --rev cannot be used with packed bundles
+  [255]
+
+  $ hg -R test bundle -t packed1 --base 0 packed.hg
+  abort: --base cannot be used with packed bundles
+  [255]
+
+packed1 doesn't yet support compression
+
+  $ hg -R test bundle -t gzip-packed1 packed.hg
+  abort: packed bundles do not yet support compression
+  [255]
+
+packed1 is produced properly
+
+  $ hg -R test bundle -t packed1 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