##// END OF EJS Templates
repair: mark the critical section of strip() as unsafe...
Augie Fackler -
r38546:6e0c66ef default
parent child Browse files
Show More
@@ -186,76 +186,77 b' def strip(ui, repo, nodelist, backup=Tru'
186 tmpbundlefile = backupbundle(repo, savebases, saveheads, node, 'temp',
186 tmpbundlefile = backupbundle(repo, savebases, saveheads, node, 'temp',
187 compress=False, obsolescence=False)
187 compress=False, obsolescence=False)
188
188
189 try:
189 with ui.uninterruptable():
190 with repo.transaction("strip") as tr:
190 try:
191 offset = len(tr.entries)
191 with repo.transaction("strip") as tr:
192 offset = len(tr.entries)
192
193
193 tr.startgroup()
194 tr.startgroup()
194 cl.strip(striprev, tr)
195 cl.strip(striprev, tr)
195 stripmanifest(repo, striprev, tr, files)
196 stripmanifest(repo, striprev, tr, files)
196
197 for fn in files:
198 repo.file(fn).strip(striprev, tr)
199 tr.endgroup()
200
197
201 for i in xrange(offset, len(tr.entries)):
198 for fn in files:
202 file, troffset, ignore = tr.entries[i]
199 repo.file(fn).strip(striprev, tr)
203 with repo.svfs(file, 'a', checkambig=True) as fp:
200 tr.endgroup()
204 fp.truncate(troffset)
205 if troffset == 0:
206 repo.store.markremoved(file)
207
201
208 deleteobsmarkers(repo.obsstore, stripobsidx)
202 for i in xrange(offset, len(tr.entries)):
209 del repo.obsstore
203 file, troffset, ignore = tr.entries[i]
210 repo.invalidatevolatilesets()
204 with repo.svfs(file, 'a', checkambig=True) as fp:
211 repo._phasecache.filterunknown(repo)
205 fp.truncate(troffset)
206 if troffset == 0:
207 repo.store.markremoved(file)
208
209 deleteobsmarkers(repo.obsstore, stripobsidx)
210 del repo.obsstore
211 repo.invalidatevolatilesets()
212 repo._phasecache.filterunknown(repo)
212
213
213 if tmpbundlefile:
214 if tmpbundlefile:
214 ui.note(_("adding branch\n"))
215 ui.note(_("adding branch\n"))
215 f = vfs.open(tmpbundlefile, "rb")
216 f = vfs.open(tmpbundlefile, "rb")
216 gen = exchange.readbundle(ui, f, tmpbundlefile, vfs)
217 gen = exchange.readbundle(ui, f, tmpbundlefile, vfs)
217 if not repo.ui.verbose:
218 if not repo.ui.verbose:
218 # silence internal shuffling chatter
219 # silence internal shuffling chatter
219 repo.ui.pushbuffer()
220 repo.ui.pushbuffer()
220 tmpbundleurl = 'bundle:' + vfs.join(tmpbundlefile)
221 tmpbundleurl = 'bundle:' + vfs.join(tmpbundlefile)
221 txnname = 'strip'
222 txnname = 'strip'
222 if not isinstance(gen, bundle2.unbundle20):
223 if not isinstance(gen, bundle2.unbundle20):
223 txnname = "strip\n%s" % util.hidepassword(tmpbundleurl)
224 txnname = "strip\n%s" % util.hidepassword(tmpbundleurl)
224 with repo.transaction(txnname) as tr:
225 with repo.transaction(txnname) as tr:
225 bundle2.applybundle(repo, gen, tr, source='strip',
226 bundle2.applybundle(repo, gen, tr, source='strip',
226 url=tmpbundleurl)
227 url=tmpbundleurl)
227 if not repo.ui.verbose:
228 if not repo.ui.verbose:
228 repo.ui.popbuffer()
229 repo.ui.popbuffer()
229 f.close()
230 f.close()
230
231
231 with repo.transaction('repair') as tr:
232 with repo.transaction('repair') as tr:
232 bmchanges = [(m, repo[newbmtarget].node()) for m in updatebm]
233 bmchanges = [(m, repo[newbmtarget].node()) for m in updatebm]
233 bm.applychanges(repo, tr, bmchanges)
234 bm.applychanges(repo, tr, bmchanges)
234
235
235 # remove undo files
236 # remove undo files
236 for undovfs, undofile in repo.undofiles():
237 for undovfs, undofile in repo.undofiles():
237 try:
238 try:
238 undovfs.unlink(undofile)
239 undovfs.unlink(undofile)
239 except OSError as e:
240 except OSError as e:
240 if e.errno != errno.ENOENT:
241 if e.errno != errno.ENOENT:
241 ui.warn(_('error removing %s: %s\n') %
242 ui.warn(_('error removing %s: %s\n') %
242 (undovfs.join(undofile),
243 (undovfs.join(undofile),
243 stringutil.forcebytestr(e)))
244 stringutil.forcebytestr(e)))
244
245
245 except: # re-raises
246 except: # re-raises
246 if backupfile:
247 if backupfile:
247 ui.warn(_("strip failed, backup bundle stored in '%s'\n")
248 ui.warn(_("strip failed, backup bundle stored in '%s'\n")
248 % vfs.join(backupfile))
249 % vfs.join(backupfile))
249 if tmpbundlefile:
250 if tmpbundlefile:
250 ui.warn(_("strip failed, unrecovered changes stored in '%s'\n")
251 ui.warn(_("strip failed, unrecovered changes stored in '%s'\n")
251 % vfs.join(tmpbundlefile))
252 % vfs.join(tmpbundlefile))
252 ui.warn(_("(fix the problem, then recover the changesets with "
253 ui.warn(_("(fix the problem, then recover the changesets with "
253 "\"hg unbundle '%s'\")\n") % vfs.join(tmpbundlefile))
254 "\"hg unbundle '%s'\")\n") % vfs.join(tmpbundlefile))
254 raise
255 raise
255 else:
256 else:
256 if tmpbundlefile:
257 if tmpbundlefile:
257 # Remove temporary bundle only if there were no exceptions
258 # Remove temporary bundle only if there were no exceptions
258 vfs.unlink(tmpbundlefile)
259 vfs.unlink(tmpbundlefile)
259
260
260 repo.destroyed()
261 repo.destroyed()
261 # return the backup file path (or None if 'backup' was False) so
262 # return the backup file path (or None if 'backup' was False) so
General Comments 0
You need to be logged in to leave comments. Login now