Mercurial > hg
comparison mercurial/repair.py @ 11791:00cde9bddbe4
repair: do not compress partial bundle if we do not keep it on disk
A partial bundle is created to temporarily save revisions > rev but
not descending from the node to strip, to be able to restore the
changesets after stripping the changelog.
Since this bundle is not kept after the strip operation, and is not
user-visible, it is not necessary and should be faster to avoid
compression.
author | Nicolas Dumazet <nicdumz.commits@gmail.com> |
---|---|
date | Thu, 12 Aug 2010 16:53:23 +0900 |
parents | 76454cbc11e4 |
children | 798ef5b19cb1 |
comparison
equal
deleted
inserted
replaced
11790:ba9957bcfb7c | 11791:00cde9bddbe4 |
---|---|
9 import changegroup | 9 import changegroup |
10 from node import nullrev, short | 10 from node import nullrev, short |
11 from i18n import _ | 11 from i18n import _ |
12 import os | 12 import os |
13 | 13 |
14 def _bundle(repo, bases, heads, node, suffix, extranodes=None): | 14 def _bundle(repo, bases, heads, node, suffix, extranodes=None, 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 = repo.changegroupsubset(bases, heads, 'strip', extranodes) | 16 cg = repo.changegroupsubset(bases, heads, 'strip', extranodes) |
17 backupdir = repo.join("strip-backup") | 17 backupdir = repo.join("strip-backup") |
18 if not os.path.isdir(backupdir): | 18 if not os.path.isdir(backupdir): |
19 os.mkdir(backupdir) | 19 os.mkdir(backupdir) |
20 name = os.path.join(backupdir, "%s-%s.hg" % (short(node), suffix)) | 20 name = os.path.join(backupdir, "%s-%s.hg" % (short(node), suffix)) |
21 return changegroup.writebundle(cg, name, "HG10BZ") | 21 if compress: |
22 bundletype = "HG10BZ" | |
23 else: | |
24 bundletype = "HG10UN" | |
25 return changegroup.writebundle(cg, name, bundletype) | |
22 | 26 |
23 def _collectfiles(repo, striprev): | 27 def _collectfiles(repo, striprev): |
24 """find out the filelogs affected by the strip""" | 28 """find out the filelogs affected by the strip""" |
25 files = set() | 29 files = set() |
26 | 30 |
67 def strip(ui, repo, node, backup="all"): | 71 def strip(ui, repo, node, backup="all"): |
68 cl = repo.changelog | 72 cl = repo.changelog |
69 # TODO delete the undo files, and handle undo of merge sets | 73 # TODO delete the undo files, and handle undo of merge sets |
70 striprev = cl.rev(node) | 74 striprev = cl.rev(node) |
71 | 75 |
76 keeppartialbundle = backup == 'strip' | |
77 | |
72 # Some revisions with rev > striprev may not be descendants of striprev. | 78 # Some revisions with rev > striprev may not be descendants of striprev. |
73 # We have to find these revisions and put them in a bundle, so that | 79 # We have to find these revisions and put them in a bundle, so that |
74 # we can restore them after the truncations. | 80 # we can restore them after the truncations. |
75 # To create the bundle we use repo.changegroupsubset which requires | 81 # To create the bundle we use repo.changegroupsubset which requires |
76 # the list of heads and bases of the set of interesting revisions. | 82 # the list of heads and bases of the set of interesting revisions. |
108 backupfile = None | 114 backupfile = None |
109 if backup == "all": | 115 if backup == "all": |
110 backupfile = _bundle(repo, [node], cl.heads(), node, 'backup') | 116 backupfile = _bundle(repo, [node], cl.heads(), node, 'backup') |
111 repo.ui.status(_("saved backup bundle to %s\n") % backupfile) | 117 repo.ui.status(_("saved backup bundle to %s\n") % backupfile) |
112 if saveheads or extranodes: | 118 if saveheads or extranodes: |
119 # do not compress partial bundle if we remove it from disk later | |
113 chgrpfile = _bundle(repo, savebases, saveheads, node, 'temp', | 120 chgrpfile = _bundle(repo, savebases, saveheads, node, 'temp', |
114 extranodes) | 121 extranodes=extranodes, compress=keeppartialbundle) |
115 | 122 |
116 mfst = repo.manifest | 123 mfst = repo.manifest |
117 | 124 |
118 tr = repo.transaction("strip") | 125 tr = repo.transaction("strip") |
119 offset = len(tr.entries) | 126 offset = len(tr.entries) |
144 repo.ui.pushbuffer() | 151 repo.ui.pushbuffer() |
145 repo.addchangegroup(gen, 'strip', 'bundle:' + chgrpfile, True) | 152 repo.addchangegroup(gen, 'strip', 'bundle:' + chgrpfile, True) |
146 if not repo.ui.verbose: | 153 if not repo.ui.verbose: |
147 repo.ui.popbuffer() | 154 repo.ui.popbuffer() |
148 f.close() | 155 f.close() |
149 if backup != "strip": | 156 if not keeppartialbundle: |
150 os.unlink(chgrpfile) | 157 os.unlink(chgrpfile) |
151 except: | 158 except: |
152 if backupfile: | 159 if backupfile: |
153 ui.warn(_("strip failed, full bundle stored in '%s'\n") | 160 ui.warn(_("strip failed, full bundle stored in '%s'\n") |
154 % backupfile) | 161 % backupfile) |