Patchwork [2,of,2] repair: add experimental option to write bundle2 files

login
register
mail settings
Submitter Eric Sumner
Date Jan. 17, 2015, 12:17 a.m.
Message ID <1df96a1a7db2124dbff9.1421453821@dev911.prn1.facebook.com>
Download mbox | patch
Permalink /patch/7503/
State Accepted
Commit b21c2e0ee8a3bbb729cab292d9751cbbfc7ffc9b
Headers show

Comments

Eric Sumner - Jan. 17, 2015, 12:17 a.m.
# HG changeset patch
# User Eric Sumner <ericsumner@fb.com>
# Date 1421369473 28800
#      Thu Jan 15 16:51:13 2015 -0800
# Node ID 1df96a1a7db2124dbff998b091118ebc008bc38a
# Parent  f4f4097f9e8b4303f3f143b025fb68dc17e42db1
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.
Matt Mackall - Jan. 17, 2015, 12:52 a.m.
On Fri, 2015-01-16 at 16:17 -0800, Eric Sumner wrote:
> # HG changeset patch
> # User Eric Sumner <ericsumner@fb.com>
> # Date 1421369473 28800
> #      Thu Jan 15 16:51:13 2015 -0800
> # Node ID 1df96a1a7db2124dbff998b091118ebc008bc38a
> # Parent  f4f4097f9e8b4303f3f143b025fb68dc17e42db1
> repair: add experimental option to write bundle2 files

These are queued for default, thanks.

Patch

diff --git a/mercurial/repair.py b/mercurial/repair.py
--- a/mercurial/repair.py
+++ b/mercurial/repair.py
@@ -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()
diff --git a/tests/test-strip.t b/tests/test-strip.t
--- a/tests/test-strip.t
+++ b/tests/test-strip.t
@@ -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