Mercurial > hg
comparison mercurial/repair.py @ 20979:ad5b61370514
repair: make "strip()" treat bundle files via vfs
This patch makes "repair.strip()" treat bundle files via vfs.
This patch also avoids applying "vfs.join()" on the value returned by
"changegroup.writebundle()", to get relative path from "_bundle()".
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Sun, 09 Mar 2014 01:03:28 +0900 |
parents | a57dcd11be34 |
children | 7ca4f2049d3b |
comparison
equal
deleted
inserted
replaced
20978:5b58714e97ed | 20979:ad5b61370514 |
---|---|
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 | 9 from mercurial import changegroup |
10 from mercurial.node import short | 10 from mercurial.node import short |
11 from mercurial.i18n import _ | 11 from mercurial.i18n import _ |
12 import os | |
13 import errno | 12 import errno |
14 | 13 |
15 def _bundle(repo, bases, heads, node, suffix, compress=True): | 14 def _bundle(repo, bases, heads, node, suffix, compress=True): |
16 """create a bundle with the specified revisions as a backup""" | 15 """create a bundle with the specified revisions as a backup""" |
17 cg = changegroup.changegroupsubset(repo, bases, heads, 'strip') | 16 cg = changegroup.changegroupsubset(repo, bases, heads, 'strip') |
22 name = "%s/%s-%s.hg" % (backupdir, short(node), suffix) | 21 name = "%s/%s-%s.hg" % (backupdir, short(node), suffix) |
23 if compress: | 22 if compress: |
24 bundletype = "HG10BZ" | 23 bundletype = "HG10BZ" |
25 else: | 24 else: |
26 bundletype = "HG10UN" | 25 bundletype = "HG10UN" |
27 return vfs.join(changegroup.writebundle(cg, name, bundletype, vfs)) | 26 return changegroup.writebundle(cg, name, bundletype, vfs) |
28 | 27 |
29 def _collectfiles(repo, striprev): | 28 def _collectfiles(repo, striprev): |
30 """find out the filelogs affected by the strip""" | 29 """find out the filelogs affected by the strip""" |
31 files = set() | 30 files = set() |
32 | 31 |
107 if rev in tostrip: | 106 if rev in tostrip: |
108 updatebm.append(m) | 107 updatebm.append(m) |
109 | 108 |
110 # create a changegroup for all the branches we need to keep | 109 # create a changegroup for all the branches we need to keep |
111 backupfile = None | 110 backupfile = None |
111 vfs = repo.vfs | |
112 if backup == "all": | 112 if backup == "all": |
113 backupfile = _bundle(repo, stripbases, cl.heads(), node, topic) | 113 backupfile = _bundle(repo, stripbases, cl.heads(), node, topic) |
114 repo.ui.status(_("saved backup bundle to %s\n") % backupfile) | 114 repo.ui.status(_("saved backup bundle to %s\n") % |
115 repo.ui.log("backupbundle", "saved backup bundle to %s\n", backupfile) | 115 vfs.join(backupfile)) |
116 repo.ui.log("backupbundle", "saved backup bundle to %s\n", | |
117 vfs.join(backupfile)) | |
116 if saveheads or savebases: | 118 if saveheads or savebases: |
117 # do not compress partial bundle if we remove it from disk later | 119 # do not compress partial bundle if we remove it from disk later |
118 chgrpfile = _bundle(repo, savebases, saveheads, node, 'temp', | 120 chgrpfile = _bundle(repo, savebases, saveheads, node, 'temp', |
119 compress=keeppartialbundle) | 121 compress=keeppartialbundle) |
120 | 122 |
142 tr.abort() | 144 tr.abort() |
143 raise | 145 raise |
144 | 146 |
145 if saveheads or savebases: | 147 if saveheads or savebases: |
146 ui.note(_("adding branch\n")) | 148 ui.note(_("adding branch\n")) |
147 f = open(chgrpfile, "rb") | 149 f = vfs.open(chgrpfile, "rb") |
148 gen = changegroup.readbundle(f, chgrpfile) | 150 gen = changegroup.readbundle(f, chgrpfile, vfs) |
149 if not repo.ui.verbose: | 151 if not repo.ui.verbose: |
150 # silence internal shuffling chatter | 152 # silence internal shuffling chatter |
151 repo.ui.pushbuffer() | 153 repo.ui.pushbuffer() |
152 changegroup.addchangegroup(repo, gen, 'strip', | 154 changegroup.addchangegroup(repo, gen, 'strip', |
153 'bundle:' + chgrpfile, True) | 155 'bundle:' + vfs.join(chgrpfile), True) |
154 if not repo.ui.verbose: | 156 if not repo.ui.verbose: |
155 repo.ui.popbuffer() | 157 repo.ui.popbuffer() |
156 f.close() | 158 f.close() |
157 if not keeppartialbundle: | 159 if not keeppartialbundle: |
158 os.unlink(chgrpfile) | 160 vfs.unlink(chgrpfile) |
159 | 161 |
160 # remove undo files | 162 # remove undo files |
161 for undovfs, undofile in repo.undofiles(): | 163 for undovfs, undofile in repo.undofiles(): |
162 try: | 164 try: |
163 undovfs.unlink(undofile) | 165 undovfs.unlink(undofile) |
170 bm[m] = repo[newbmtarget].node() | 172 bm[m] = repo[newbmtarget].node() |
171 bm.write() | 173 bm.write() |
172 except: # re-raises | 174 except: # re-raises |
173 if backupfile: | 175 if backupfile: |
174 ui.warn(_("strip failed, full bundle stored in '%s'\n") | 176 ui.warn(_("strip failed, full bundle stored in '%s'\n") |
175 % backupfile) | 177 % vfs.join(backupfile)) |
176 elif saveheads: | 178 elif saveheads: |
177 ui.warn(_("strip failed, partial bundle stored in '%s'\n") | 179 ui.warn(_("strip failed, partial bundle stored in '%s'\n") |
178 % chgrpfile) | 180 % vfs.join(chgrpfile)) |
179 raise | 181 raise |
180 | 182 |
181 repo.destroyed() | 183 repo.destroyed() |