Mercurial > hg
changeset 26632:59b5e8844eb0
dirstate: move code paths for backup from dirstateguard to dirstate
This can centralize the logic to write in-memory changes out correctly
according to transaction activity into dirstate.
Passing 'repo' object to newly added functions is needed to examine
current transaction activity in subsequent patches, because 'dirstate'
itself doesn't have direct reference to it.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Wed, 14 Oct 2015 02:49:17 +0900 |
parents | e077ce385609 |
children | 020b12d591f3 |
files | mercurial/cmdutil.py mercurial/dirstate.py |
diffstat | 2 files changed, 28 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Tue Oct 13 12:25:43 2015 -0700 +++ b/mercurial/cmdutil.py Wed Oct 14 02:49:17 2015 +0900 @@ -3330,10 +3330,9 @@ ''' def __init__(self, repo, name): - repo.dirstate.write() self._repo = repo - self._filename = 'dirstate.backup.%s.%d' % (name, id(self)) - repo.vfs.write(self._filename, repo.vfs.tryread('dirstate')) + self._suffix = '.backup.%s.%d' % (name, id(self)) + repo.dirstate._savebackup(repo, self._suffix) self._active = True self._closed = False @@ -3347,27 +3346,24 @@ def close(self): if not self._active: # already inactivated - msg = (_("can't close already inactivated backup: %s") - % self._filename) + msg = (_("can't close already inactivated backup: dirstate%s") + % self._suffix) raise error.Abort(msg) - self._repo.vfs.unlink(self._filename) + self._repo.dirstate._clearbackup(self._repo, self._suffix) self._active = False self._closed = True def _abort(self): - # this "invalidate()" prevents "wlock.release()" from writing - # changes of dirstate out after restoring to original status - self._repo.dirstate.invalidate() - - self._repo.vfs.rename(self._filename, 'dirstate') + self._repo.dirstate._restorebackup(self._repo, self._suffix) self._active = False def release(self): if not self._closed: if not self._active: # already inactivated - msg = (_("can't release already inactivated backup: %s") - % self._filename) + msg = (_("can't release already inactivated backup:" + " dirstate%s") + % self._suffix) raise error.Abort(msg) self._abort()
--- a/mercurial/dirstate.py Tue Oct 13 12:25:43 2015 -0700 +++ b/mercurial/dirstate.py Wed Oct 14 02:49:17 2015 +0900 @@ -1051,3 +1051,22 @@ # that return list(files) return [f for f in dmap if match(f)] + + def _savebackup(self, repo, suffix): + '''Save current dirstate into backup file with suffix''' + self.write() + filename = self._filename + self._opener.write(filename + suffix, self._opener.tryread(filename)) + + def _restorebackup(self, repo, suffix): + '''Restore dirstate by backup file with suffix''' + # this "invalidate()" prevents "wlock.release()" from writing + # changes of dirstate out after restoring from backup file + self.invalidate() + filename = self._filename + self._opener.rename(filename + suffix, filename) + + def _clearbackup(self, repo, suffix): + '''Clear backup file with suffix''' + filename = self._filename + self._opener.unlink(filename + suffix)