cmdutil: satisfy expections in dirstateguard.__del__, even if __init__ fails
authorMads Kiilerich <madski@unity3d.com>
Fri, 14 Oct 2016 01:53:15 +0200
changeset 30182 144d8fe266d9
parent 30181 7356e6b1f5b8
child 30183 0106f93ca1d5
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.]
mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Fri Oct 14 01:53:15 2016 +0200
+++ b/mercurial/cmdutil.py	Fri Oct 14 01:53:15 2016 +0200
@@ -3526,10 +3526,11 @@
 
     def __init__(self, repo, name):
         self._repo = repo
+        self._active = False
+        self._closed = False
         self._suffix = '.backup.%s.%d' % (name, id(self))
         repo.dirstate.savebackup(repo.currenttransaction(), self._suffix)
         self._active = True
-        self._closed = False
 
     def __del__(self):
         if self._active: # still active