comparison 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
comparison
equal deleted inserted replaced
16114:acfca07a8f26 16115:236bb604dc39
801 self.func = func 801 self.func = func
802 self.name = func.__name__ 802 self.name = func.__name__
803 return self 803 return self
804 804
805 def __get__(self, obj, type=None): 805 def __get__(self, obj, type=None):
806 # do we need to check if the file changed?
807 if self.name in obj.__dict__:
808 return obj.__dict__[self.name]
809
806 entry = obj._filecache.get(self.name) 810 entry = obj._filecache.get(self.name)
807 811
808 if entry: 812 if entry:
809 if entry.changed(): 813 if entry.changed():
810 entry.obj = self.func(obj) 814 entry.obj = self.func(obj)
816 entry = filecacheentry(path) 820 entry = filecacheentry(path)
817 entry.obj = self.func(obj) 821 entry.obj = self.func(obj)
818 822
819 obj._filecache[self.name] = entry 823 obj._filecache[self.name] = entry
820 824
821 setattr(obj, self.name, entry.obj) 825 obj.__dict__[self.name] = entry.obj
822 return entry.obj 826 return entry.obj
827
828 def __set__(self, obj, value):
829 if self.name in obj._filecache:
830 obj._filecache[self.name].obj = value # update cached copy
831 obj.__dict__[self.name] = value # update copy returned by obj.x
832
833 def __delete__(self, obj):
834 try:
835 del obj.__dict__[self.name]
836 except KeyError:
837 raise AttributeError, self.name