##// END OF EJS Templates
dirstate: update backup functions to take full backup filename...
Adam Simpkins -
r33440:ec306bc6 default
parent child Browse files
Show More
@@ -297,9 +297,10 b' def _aborttransaction(repo):'
297 297 '''Abort current transaction for shelve/unshelve, but keep dirstate
298 298 '''
299 299 tr = repo.currenttransaction()
300 repo.dirstate.savebackup(tr, suffix='.shelve')
300 backupname = 'dirstate.shelve'
301 repo.dirstate.savebackup(tr, backupname)
301 302 tr.abort()
302 repo.dirstate.restorebackup(None, suffix='.shelve')
303 repo.dirstate.restorebackup(None, backupname)
303 304
304 305 def createcmd(ui, repo, pats, opts):
305 306 """subcommand that creates a new shelve"""
@@ -1300,10 +1300,10 b' class dirstate(object):'
1300 1300 else:
1301 1301 return self._filename
1302 1302
1303 def savebackup(self, tr, suffix='', prefix=''):
1304 '''Save current dirstate into backup file with suffix'''
1305 assert len(suffix) > 0 or len(prefix) > 0
1303 def savebackup(self, tr, backupname):
1304 '''Save current dirstate into backup file'''
1306 1305 filename = self._actualfilename(tr)
1306 assert backupname != filename
1307 1307
1308 1308 # use '_writedirstate' instead of 'write' to write changes certainly,
1309 1309 # because the latter omits writing out if transaction is running.
@@ -1324,27 +1324,20 b' class dirstate(object):'
1324 1324 # end of this transaction
1325 1325 tr.registertmp(filename, location='plain')
1326 1326
1327 backupname = prefix + self._filename + suffix
1328 assert backupname != filename
1329 1327 self._opener.tryunlink(backupname)
1330 1328 # hardlink backup is okay because _writedirstate is always called
1331 1329 # with an "atomictemp=True" file.
1332 1330 util.copyfile(self._opener.join(filename),
1333 1331 self._opener.join(backupname), hardlink=True)
1334 1332
1335 def restorebackup(self, tr, suffix='', prefix=''):
1336 '''Restore dirstate by backup file with suffix'''
1337 assert len(suffix) > 0 or len(prefix) > 0
1333 def restorebackup(self, tr, backupname):
1334 '''Restore dirstate by backup file'''
1338 1335 # this "invalidate()" prevents "wlock.release()" from writing
1339 1336 # changes of dirstate out after restoring from backup file
1340 1337 self.invalidate()
1341 1338 filename = self._actualfilename(tr)
1342 # using self._filename to avoid having "pending" in the backup filename
1343 self._opener.rename(prefix + self._filename + suffix, filename,
1344 checkambig=True)
1339 self._opener.rename(backupname, filename, checkambig=True)
1345 1340
1346 def clearbackup(self, tr, suffix='', prefix=''):
1347 '''Clear backup file with suffix'''
1348 assert len(suffix) > 0 or len(prefix) > 0
1349 # using self._filename to avoid having "pending" in the backup filename
1350 self._opener.unlink(prefix + self._filename + suffix)
1341 def clearbackup(self, tr, backupname):
1342 '''Clear backup file'''
1343 self._opener.unlink(backupname)
@@ -31,8 +31,8 b' class dirstateguard(object):'
31 31 self._repo = repo
32 32 self._active = False
33 33 self._closed = False
34 self._suffix = '.backup.%s.%d' % (name, id(self))
35 repo.dirstate.savebackup(repo.currenttransaction(), self._suffix)
34 self._backupname = 'dirstate.backup.%s.%d' % (name, id(self))
35 repo.dirstate.savebackup(repo.currenttransaction(), self._backupname)
36 36 self._active = True
37 37
38 38 def __del__(self):
@@ -45,25 +45,24 b' class dirstateguard(object):'
45 45
46 46 def close(self):
47 47 if not self._active: # already inactivated
48 msg = (_("can't close already inactivated backup: dirstate%s")
49 % self._suffix)
48 msg = (_("can't close already inactivated backup: %s")
49 % self._backupname)
50 50 raise error.Abort(msg)
51 51
52 52 self._repo.dirstate.clearbackup(self._repo.currenttransaction(),
53 self._suffix)
53 self._backupname)
54 54 self._active = False
55 55 self._closed = True
56 56
57 57 def _abort(self):
58 58 self._repo.dirstate.restorebackup(self._repo.currenttransaction(),
59 self._suffix)
59 self._backupname)
60 60 self._active = False
61 61
62 62 def release(self):
63 63 if not self._closed:
64 64 if not self._active: # already inactivated
65 msg = (_("can't release already inactivated backup:"
66 " dirstate%s")
67 % self._suffix)
65 msg = (_("can't release already inactivated backup: %s")
66 % self._backupname)
68 67 raise error.Abort(msg)
69 68 self._abort()
@@ -1202,7 +1202,7 b' class localrepository(object):'
1202 1202 else:
1203 1203 # discard all changes (including ones already written
1204 1204 # out) in this transaction
1205 repo.dirstate.restorebackup(None, prefix='journal.')
1205 repo.dirstate.restorebackup(None, 'journal.dirstate')
1206 1206
1207 1207 repo.invalidate(clearfilecache=True)
1208 1208
@@ -1262,7 +1262,7 b' class localrepository(object):'
1262 1262
1263 1263 @unfilteredmethod
1264 1264 def _writejournal(self, desc):
1265 self.dirstate.savebackup(None, prefix='journal.')
1265 self.dirstate.savebackup(None, 'journal.dirstate')
1266 1266 self.vfs.write("journal.branch",
1267 1267 encoding.fromlocal(self.dirstate.branch()))
1268 1268 self.vfs.write("journal.desc",
@@ -1350,7 +1350,7 b' class localrepository(object):'
1350 1350 # prevent dirstateguard from overwriting already restored one
1351 1351 dsguard.close()
1352 1352
1353 self.dirstate.restorebackup(None, prefix='undo.')
1353 self.dirstate.restorebackup(None, 'undo.dirstate')
1354 1354 try:
1355 1355 branch = self.vfs.read('undo.branch')
1356 1356 self.dirstate.setbranch(encoding.tolocal(branch))
General Comments 0
You need to be logged in to leave comments. Login now