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