Mercurial > public > mercurial-scm > hg
comparison mercurial/cmdutil.py @ 30182:144d8fe266d9
cmdutil: satisfy expections in dirstateguard.__del__, even if __init__ fails
Python "delstructors" are terrible - this one because it assumed that __init__
had completed before it was called. That would not necessarily be the case if
the repository was read only or broken and saving the dirstate thus failed in
unexpected ways. That could give confusing warnings about missing '_active'
after failures.
To fix that, make sure all member variables are "declared" before doing
anything that possibly could fail. [Famous last words.]
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Fri, 14 Oct 2016 01:53:15 +0200 |
parents | 381293e1135e |
children | 3d38a0bc774f |
comparison
equal
deleted
inserted
replaced
30181:7356e6b1f5b8 | 30182:144d8fe266d9 |
---|---|
3524 This just removes the backup file at ``close()`` before ``release()``. | 3524 This just removes the backup file at ``close()`` before ``release()``. |
3525 ''' | 3525 ''' |
3526 | 3526 |
3527 def __init__(self, repo, name): | 3527 def __init__(self, repo, name): |
3528 self._repo = repo | 3528 self._repo = repo |
3529 self._active = False | |
3530 self._closed = False | |
3529 self._suffix = '.backup.%s.%d' % (name, id(self)) | 3531 self._suffix = '.backup.%s.%d' % (name, id(self)) |
3530 repo.dirstate.savebackup(repo.currenttransaction(), self._suffix) | 3532 repo.dirstate.savebackup(repo.currenttransaction(), self._suffix) |
3531 self._active = True | 3533 self._active = True |
3532 self._closed = False | |
3533 | 3534 |
3534 def __del__(self): | 3535 def __del__(self): |
3535 if self._active: # still active | 3536 if self._active: # still active |
3536 # this may occur, even if this class is used correctly: | 3537 # this may occur, even if this class is used correctly: |
3537 # for example, releasing other resources like transaction | 3538 # for example, releasing other resources like transaction |