Mercurial > hg
comparison hgext/shelve.py @ 29270:48b38b16a8f8
shelve: use backup functions instead of manually copying dirstate
This increases encapsulation of dirstate: the dirstate file is private
to the dirstate module and shouldn't be touched by extensions directly.
author | Mateusz Kwapich <mitrandir@fb.com> |
---|---|
date | Tue, 24 May 2016 13:29:53 -0700 |
parents | a0939666b836 |
children | b17a6e3cd2ac |
comparison
equal
deleted
inserted
replaced
29269:b6f9934cf10b | 29270:48b38b16a8f8 |
---|---|
224 raise | 224 raise |
225 | 225 |
226 def _aborttransaction(repo): | 226 def _aborttransaction(repo): |
227 '''Abort current transaction for shelve/unshelve, but keep dirstate | 227 '''Abort current transaction for shelve/unshelve, but keep dirstate |
228 ''' | 228 ''' |
229 backupname = 'dirstate.shelve' | 229 tr = repo.currenttransaction() |
230 dirstatebackup = None | 230 repo.dirstate.savebackup(tr, suffix='.shelve') |
231 try: | 231 tr.abort() |
232 # create backup of (un)shelved dirstate, because aborting transaction | 232 repo.dirstate.restorebackup(None, suffix='.shelve') |
233 # should restore dirstate to one at the beginning of the | |
234 # transaction, which doesn't include the result of (un)shelving | |
235 fp = repo.vfs.open(backupname, "w") | |
236 dirstatebackup = backupname | |
237 # clearing _dirty/_dirtypl of dirstate by _writedirstate below | |
238 # is unintentional. but it doesn't cause problem in this case, | |
239 # because no code path refers them until transaction is aborted. | |
240 repo.dirstate._writedirstate(fp) # write in-memory changes forcibly | |
241 | |
242 tr = repo.currenttransaction() | |
243 tr.abort() | |
244 | |
245 # restore to backuped dirstate | |
246 repo.vfs.rename(dirstatebackup, 'dirstate') | |
247 dirstatebackup = None | |
248 finally: | |
249 if dirstatebackup: | |
250 repo.vfs.unlink(dirstatebackup) | |
251 | 233 |
252 def createcmd(ui, repo, pats, opts): | 234 def createcmd(ui, repo, pats, opts): |
253 """subcommand that creates a new shelve""" | 235 """subcommand that creates a new shelve""" |
254 with repo.wlock(): | 236 with repo.wlock(): |
255 cmdutil.checkunfinished(repo) | 237 cmdutil.checkunfinished(repo) |