comparison mercurial/cmdutil.py @ 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 56b2bcea2529
children 92d67e5729b9
comparison
equal deleted inserted replaced
26631:e077ce385609 26632:59b5e8844eb0
3328 3328
3329 This just removes the backup file at ``close()`` before ``release()``. 3329 This just removes the backup file at ``close()`` before ``release()``.
3330 ''' 3330 '''
3331 3331
3332 def __init__(self, repo, name): 3332 def __init__(self, repo, name):
3333 repo.dirstate.write()
3334 self._repo = repo 3333 self._repo = repo
3335 self._filename = 'dirstate.backup.%s.%d' % (name, id(self)) 3334 self._suffix = '.backup.%s.%d' % (name, id(self))
3336 repo.vfs.write(self._filename, repo.vfs.tryread('dirstate')) 3335 repo.dirstate._savebackup(repo, self._suffix)
3337 self._active = True 3336 self._active = True
3338 self._closed = False 3337 self._closed = False
3339 3338
3340 def __del__(self): 3339 def __del__(self):
3341 if self._active: # still active 3340 if self._active: # still active
3345 # ``release(tr, ....)``. 3344 # ``release(tr, ....)``.
3346 self._abort() 3345 self._abort()
3347 3346
3348 def close(self): 3347 def close(self):
3349 if not self._active: # already inactivated 3348 if not self._active: # already inactivated
3350 msg = (_("can't close already inactivated backup: %s") 3349 msg = (_("can't close already inactivated backup: dirstate%s")
3351 % self._filename) 3350 % self._suffix)
3352 raise error.Abort(msg) 3351 raise error.Abort(msg)
3353 3352
3354 self._repo.vfs.unlink(self._filename) 3353 self._repo.dirstate._clearbackup(self._repo, self._suffix)
3355 self._active = False 3354 self._active = False
3356 self._closed = True 3355 self._closed = True
3357 3356
3358 def _abort(self): 3357 def _abort(self):
3359 # this "invalidate()" prevents "wlock.release()" from writing 3358 self._repo.dirstate._restorebackup(self._repo, self._suffix)
3360 # changes of dirstate out after restoring to original status
3361 self._repo.dirstate.invalidate()
3362
3363 self._repo.vfs.rename(self._filename, 'dirstate')
3364 self._active = False 3359 self._active = False
3365 3360
3366 def release(self): 3361 def release(self):
3367 if not self._closed: 3362 if not self._closed:
3368 if not self._active: # already inactivated 3363 if not self._active: # already inactivated
3369 msg = (_("can't release already inactivated backup: %s") 3364 msg = (_("can't release already inactivated backup:"
3370 % self._filename) 3365 " dirstate%s")
3366 % self._suffix)
3371 raise error.Abort(msg) 3367 raise error.Abort(msg)
3372 self._abort() 3368 self._abort()
3373 3369
3374 _bundlecompspecs = {'none': None, 3370 _bundlecompspecs = {'none': None,
3375 'bzip2': 'BZ', 3371 'bzip2': 'BZ',