commands: support consuming stream clone bundles
authorGregory Szorc <gregory.szorc@gmail.com>
Thu, 15 Oct 2015 13:43:18 -0700
changeset 26758 bde7ef23340d
parent 26757 43708f92f471
child 26759 c0f475ac997e
commands: support consuming stream clone bundles For the same reasons that we don't produce stream clone bundles with `hg bundle`, we don't support consuming stream clone bundles with `hg unbundle`. We introduce a complementary debug command for applying stream clone bundles. This command is mostly to facilitate testing. Although it may be used to manually apply stream clone bundles until a more formal mechanism is (possibly) adopted.
mercurial/commands.py
tests/test-bundle.t
tests/test-completion.t
tests/test-help.t
--- a/mercurial/commands.py	Sat Oct 17 11:40:29 2015 -0700
+++ b/mercurial/commands.py	Thu Oct 15 13:43:18 2015 -0700
@@ -1978,6 +1978,13 @@
 
     ui.write(_('bundle requirements: %s\n') % ', '.join(sorted(requirements)))
 
+@command('debugapplystreamclonebundle', [], 'FILE')
+def debugapplystreamclonebundle(ui, repo, fname):
+    """apply a stream clone bundle file"""
+    f = hg.openpath(ui, fname)
+    gen = exchange.readbundle(ui, f, fname)
+    gen.apply(repo)
+
 @command('debugcheckstate', [], '')
 def debugcheckstate(ui, repo):
     """validate the correctness of the current dirstate"""
@@ -6532,6 +6539,11 @@
                 changes = [r.get('return', 0)
                            for r in op.records['changegroup']]
                 modheads = changegroup.combineresults(changes)
+            elif isinstance(gen, streamclone.streamcloneapplier):
+                raise error.Abort(
+                        _('packed bundles cannot be applied with '
+                          '"hg unbundle"'),
+                        hint=_('use "hg debugapplystreamclonebundle"'))
             else:
                 modheads = gen.apply(repo, 'unbundle', 'bundle:' + fname)
     finally:
--- a/tests/test-bundle.t	Sat Oct 17 11:40:29 2015 -0700
+++ b/tests/test-bundle.t	Thu Oct 15 13:43:18 2015 -0700
@@ -288,6 +288,26 @@
   0020: 65 6c 74 61 2c 72 65 76 6c 6f 67 76 31 00 64 61 |elta,revlogv1.da|
   0030: 74 61 2f 66 6f 6f 2e 69 00 36 34 0a 00 03 00 01 |ta/foo.i.64.....|
 
+Unpacking packed1 bundles with "hg unbundle" isn't allowed
+
+  $ hg init packed
+  $ hg -R packed unbundle packed.hg
+  abort: packed bundles cannot be applied with "hg unbundle"
+  (use "hg debugapplystreamclonebundle")
+  [255]
+
+packed1 can be consumed from debug command
+
+  $ hg -R packed debugapplystreamclonebundle packed.hg
+  6 files to transfer, 2.55 KB of data
+  transferred 2.55 KB in *.* seconds (*) (glob)
+
+Does not work on non-empty repo
+
+  $ hg -R packed debugapplystreamclonebundle packed.hg
+  abort: cannot apply stream clone bundle on non-empty repo
+  [255]
+
 Create partial clones
 
   $ rm -r empty
--- a/tests/test-completion.t	Sat Oct 17 11:40:29 2015 -0700
+++ b/tests/test-completion.t	Thu Oct 15 13:43:18 2015 -0700
@@ -69,6 +69,7 @@
 Show debug commands if there are no other candidates
   $ hg debugcomplete debug
   debugancestor
+  debugapplystreamclonebundle
   debugbuilddag
   debugbundle
   debugcheckstate
@@ -232,6 +233,7 @@
   config: untrusted, edit, local, global
   copy: after, force, include, exclude, dry-run
   debugancestor: 
+  debugapplystreamclonebundle: 
   debugbuilddag: mergeable-file, overwritten-file, new-file
   debugbundle: all
   debugcheckstate: 
--- a/tests/test-help.t	Sat Oct 17 11:40:29 2015 -0700
+++ b/tests/test-help.t	Thu Oct 15 13:43:18 2015 -0700
@@ -781,6 +781,8 @@
   
    debugancestor
                  find the ancestor revision of two revisions in a given index
+   debugapplystreamclonebundle
+                 apply a stream clone bundle file
    debugbuilddag
                  builds a repo with a given DAG from scratch in the current
                  empty repo
@@ -1068,6 +1070,7 @@
   
    bookmarks                    create a new bookmark or list existing bookmarks
    clone                        make a copy of an existing repository
+   debugapplystreamclonebundle  apply a stream clone bundle file
    debugcreatestreamclonebundle create a stream clone bundle file
    paths                        show aliases for remote repositories
    update                       update working directory (or switch revisions)