Mercurial > hg-stable
changeset 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 | b6f9934cf10b |
children | 118a605e3ad9 |
files | hgext/shelve.py |
diffstat | 1 files changed, 4 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/shelve.py Wed May 25 16:36:16 2016 -0700 +++ b/hgext/shelve.py Tue May 24 13:29:53 2016 -0700 @@ -226,28 +226,10 @@ def _aborttransaction(repo): '''Abort current transaction for shelve/unshelve, but keep dirstate ''' - backupname = 'dirstate.shelve' - dirstatebackup = None - try: - # create backup of (un)shelved dirstate, because aborting transaction - # should restore dirstate to one at the beginning of the - # transaction, which doesn't include the result of (un)shelving - fp = repo.vfs.open(backupname, "w") - dirstatebackup = backupname - # clearing _dirty/_dirtypl of dirstate by _writedirstate below - # is unintentional. but it doesn't cause problem in this case, - # because no code path refers them until transaction is aborted. - repo.dirstate._writedirstate(fp) # write in-memory changes forcibly - - tr = repo.currenttransaction() - tr.abort() - - # restore to backuped dirstate - repo.vfs.rename(dirstatebackup, 'dirstate') - dirstatebackup = None - finally: - if dirstatebackup: - repo.vfs.unlink(dirstatebackup) + tr = repo.currenttransaction() + repo.dirstate.savebackup(tr, suffix='.shelve') + tr.abort() + repo.dirstate.restorebackup(None, suffix='.shelve') def createcmd(ui, repo, pats, opts): """subcommand that creates a new shelve"""