4 # Copyright 2007 Matt Mackall |
4 # Copyright 2007 Matt Mackall |
5 # |
5 # |
6 # This software may be used and distributed according to the terms of the |
6 # This software may be used and distributed according to the terms of the |
7 # GNU General Public License version 2 or any later version. |
7 # GNU General Public License version 2 or any later version. |
8 |
8 |
9 from mercurial import changegroup, exchange, util |
9 from mercurial import changegroup, exchange, util, bundle2 |
10 from mercurial.node import short, hex |
10 from mercurial.node import short, hex |
11 from mercurial.i18n import _ |
11 from mercurial.i18n import _ |
12 import errno |
12 import errno |
13 |
13 |
14 def _bundle(repo, bases, heads, node, suffix, compress=True): |
14 def _bundle(repo, bases, heads, node, suffix, compress=True): |
15 """create a bundle with the specified revisions as a backup""" |
15 """create a bundle with the specified revisions as a backup""" |
16 cg = changegroup.changegroupsubset(repo, bases, heads, 'strip') |
16 usebundle2 = (repo.ui.config('experimental', 'bundle2-exp') and |
|
17 repo.ui.config('experimental', 'strip-bundle2-version')) |
|
18 if usebundle2: |
|
19 cgversion = repo.ui.config('experimental', 'strip-bundle2-version') |
|
20 else: |
|
21 cgversion = '01' |
|
22 |
|
23 cg = changegroup.changegroupsubset(repo, bases, heads, 'strip', |
|
24 version=cgversion) |
17 backupdir = "strip-backup" |
25 backupdir = "strip-backup" |
18 vfs = repo.vfs |
26 vfs = repo.vfs |
19 if not vfs.isdir(backupdir): |
27 if not vfs.isdir(backupdir): |
20 vfs.mkdir(backupdir) |
28 vfs.mkdir(backupdir) |
21 |
29 |
25 allcommits = repo.set('%ls::%ls', hexbases, hexheads) |
33 allcommits = repo.set('%ls::%ls', hexbases, hexheads) |
26 allhashes = sorted(c.hex() for c in allcommits) |
34 allhashes = sorted(c.hex() for c in allcommits) |
27 totalhash = util.sha1(''.join(allhashes)).hexdigest() |
35 totalhash = util.sha1(''.join(allhashes)).hexdigest() |
28 name = "%s/%s-%s-%s.hg" % (backupdir, short(node), totalhash[:8], suffix) |
36 name = "%s/%s-%s-%s.hg" % (backupdir, short(node), totalhash[:8], suffix) |
29 |
37 |
30 if compress: |
38 if usebundle2: |
|
39 bundletype = "HG2Y" |
|
40 elif compress: |
31 bundletype = "HG10BZ" |
41 bundletype = "HG10BZ" |
32 else: |
42 else: |
33 bundletype = "HG10UN" |
43 bundletype = "HG10UN" |
34 return changegroup.writebundle(repo.ui, cg, name, bundletype, vfs) |
44 return changegroup.writebundle(repo.ui, cg, name, bundletype, vfs) |
35 |
45 |
161 f = vfs.open(chgrpfile, "rb") |
171 f = vfs.open(chgrpfile, "rb") |
162 gen = exchange.readbundle(ui, f, chgrpfile, vfs) |
172 gen = exchange.readbundle(ui, f, chgrpfile, vfs) |
163 if not repo.ui.verbose: |
173 if not repo.ui.verbose: |
164 # silence internal shuffling chatter |
174 # silence internal shuffling chatter |
165 repo.ui.pushbuffer() |
175 repo.ui.pushbuffer() |
166 changegroup.addchangegroup(repo, gen, 'strip', |
176 if isinstance(gen, bundle2.unbundle20): |
167 'bundle:' + vfs.join(chgrpfile), True) |
177 tr = repo.transaction('strip') |
|
178 try: |
|
179 bundle2.processbundle(repo, gen, lambda: tr) |
|
180 tr.close() |
|
181 finally: |
|
182 tr.release() |
|
183 else: |
|
184 changegroup.addchangegroup(repo, gen, 'strip', |
|
185 'bundle:' + vfs.join(chgrpfile), |
|
186 True) |
168 if not repo.ui.verbose: |
187 if not repo.ui.verbose: |
169 repo.ui.popbuffer() |
188 repo.ui.popbuffer() |
170 f.close() |
189 f.close() |
171 |
190 |
172 # remove undo files |
191 # remove undo files |