diff mercurial/scmutil.py @ 16115:236bb604dc39 stable

scmutil: update cached copy when filecached attribute is assigned (issue3263) When assigning a new object to filecached properties, the cached object that was kept in the _filecache map was still holding the old object. By implementing __set__, we track these changes too and update the cached copy as well.
author Idan Kamara <idankk86@gmail.com>
date Wed, 15 Feb 2012 20:02:35 +0200
parents 73aaff46175b
children 94a8396c9305 fa8488565afd
line wrap: on
line diff
--- a/mercurial/scmutil.py	Wed Feb 15 23:44:10 2012 +0200
+++ b/mercurial/scmutil.py	Wed Feb 15 20:02:35 2012 +0200
@@ -803,6 +803,10 @@
         return self
 
     def __get__(self, obj, type=None):
+        # do we need to check if the file changed?
+        if self.name in obj.__dict__:
+            return obj.__dict__[self.name]
+
         entry = obj._filecache.get(self.name)
 
         if entry:
@@ -818,5 +822,16 @@
 
             obj._filecache[self.name] = entry
 
-        setattr(obj, self.name, entry.obj)
+        obj.__dict__[self.name] = entry.obj
         return entry.obj
+
+    def __set__(self, obj, value):
+        if self.name in obj._filecache:
+            obj._filecache[self.name].obj = value # update cached copy
+        obj.__dict__[self.name] = value # update copy returned by obj.x
+
+    def __delete__(self, obj):
+        try:
+            del obj.__dict__[self.name]
+        except KeyError:
+            raise AttributeError, self.name