changeset 23898:b21c2e0ee8a3

repair: add experimental option to write bundle2 files This adds an experimental option 'strip-bundle2-version' which causes backup bundles to use bundle2 formatting. Especially for generaldelta repositories, this should provide significant performance gains for any operation that needs to write a backup.
author Eric Sumner <ericsumner@fb.com>
date Thu, 15 Jan 2015 16:51:13 -0800
parents f99a6e1865e5
children 4e451d1359de
files mercurial/repair.py tests/test-strip.t
diffstat 2 files changed, 48 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/repair.py	Thu Jan 15 15:55:13 2015 -0800
+++ b/mercurial/repair.py	Thu Jan 15 16:51:13 2015 -0800
@@ -6,14 +6,22 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
-from mercurial import changegroup, exchange, util
+from mercurial import changegroup, exchange, util, bundle2
 from mercurial.node import short, hex
 from mercurial.i18n import _
 import errno
 
 def _bundle(repo, bases, heads, node, suffix, compress=True):
     """create a bundle with the specified revisions as a backup"""
-    cg = changegroup.changegroupsubset(repo, bases, heads, 'strip')
+    usebundle2 = (repo.ui.config('experimental', 'bundle2-exp') and
+                  repo.ui.config('experimental', 'strip-bundle2-version'))
+    if usebundle2:
+        cgversion = repo.ui.config('experimental', 'strip-bundle2-version')
+    else:
+        cgversion = '01'
+
+    cg = changegroup.changegroupsubset(repo, bases, heads, 'strip',
+                                       version=cgversion)
     backupdir = "strip-backup"
     vfs = repo.vfs
     if not vfs.isdir(backupdir):
@@ -27,7 +35,9 @@
     totalhash = util.sha1(''.join(allhashes)).hexdigest()
     name = "%s/%s-%s-%s.hg" % (backupdir, short(node), totalhash[:8], suffix)
 
-    if compress:
+    if usebundle2:
+        bundletype = "HG2Y"
+    elif compress:
         bundletype = "HG10BZ"
     else:
         bundletype = "HG10UN"
@@ -163,8 +173,17 @@
             if not repo.ui.verbose:
                 # silence internal shuffling chatter
                 repo.ui.pushbuffer()
-            changegroup.addchangegroup(repo, gen, 'strip',
-                                       'bundle:' + vfs.join(chgrpfile), True)
+            if isinstance(gen, bundle2.unbundle20):
+                tr = repo.transaction('strip')
+                try:
+                    bundle2.processbundle(repo, gen, lambda: tr)
+                    tr.close()
+                finally:
+                    tr.release()
+            else:
+                changegroup.addchangegroup(repo, gen, 'strip',
+                                           'bundle:' + vfs.join(chgrpfile),
+                                           True)
             if not repo.ui.verbose:
                 repo.ui.popbuffer()
             f.close()
--- a/tests/test-strip.t	Thu Jan 15 15:55:13 2015 -0800
+++ b/tests/test-strip.t	Thu Jan 15 16:51:13 2015 -0800
@@ -187,6 +187,30 @@
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     a
   
+  $ hg up -C 4
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg parents
+  changeset:   4:264128213d29
+  tag:         tip
+  parent:      1:ef3a871183d7
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     c
+  
+  $ hg --config experimental.bundle2-exp=True --config experimental.strip-bundle2-version=02 --traceback strip 4
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  saved backup bundle to $TESTTMP/test/.hg/strip-backup/264128213d29-0b39d6bf-backup.hg (glob)
+  $ hg parents
+  changeset:   1:ef3a871183d7
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     b
+  
+  $ hg debugbundle .hg/strip-backup/*
+  Stream params: {}
+  b2x:changegroup -- "{'version': '02'}"
+      264128213d290d868c54642d13aeaa3675551a78
+  $ restore
 
   $ hg up -C 2
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved