# HG changeset patch # User Eric Sumner # Date 2015-01-16 00:51:13 # Node ID b21c2e0ee8a3bbb729cab292d9751cbbfc7ffc9b # Parent f99a6e1865e5a25a47b670cde72a679494df888f 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. 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 @@ def _bundle(repo, bases, heads, node, su 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 @@ def strip(ui, repo, nodelist, backup=Tru 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