comparison mercurial/scmutil.py @ 18316:f36375576ed5

filecache: create an entry in _filecache when __set__ is called for a missing one Preserve the invariant that if P is a filecached property on X then P in X.__dict__ => P in X._filecache. Previously, it was possible for a filecached property to become out of sync with the filesystem if it was set before getting it first, since the initial filecacheentry was created in __get__. Old behaviour: repo.prop = x repo.invalidate() # prop has no entry in _filecache, it's not removed # from __dict__ repo.prop # returns x like before without checking with the # filesystem New: repo.prop = x # an empty entry is created in _filecache repo.invalidate() # prop is removed from __dict__ repo.prop # recreates prop
author Idan Kamara <idankk86@gmail.com>
date Mon, 17 Dec 2012 15:25:45 +0200
parents 216230643ae2
children 4aecdb91443c
comparison
equal deleted inserted replaced
18315:216230643ae2 18316:f36375576ed5
948 return self 948 return self
949 949
950 def __get__(self, obj, type=None): 950 def __get__(self, obj, type=None):
951 # do we need to check if the file changed? 951 # do we need to check if the file changed?
952 if self.name in obj.__dict__: 952 if self.name in obj.__dict__:
953 assert self.name in obj._filecache, self.name
953 return obj.__dict__[self.name] 954 return obj.__dict__[self.name]
954 955
955 entry = obj._filecache.get(self.name) 956 entry = obj._filecache.get(self.name)
956 957
957 if entry: 958 if entry:
969 970
970 obj.__dict__[self.name] = entry.obj 971 obj.__dict__[self.name] = entry.obj
971 return entry.obj 972 return entry.obj
972 973
973 def __set__(self, obj, value): 974 def __set__(self, obj, value):
974 if self.name in obj._filecache: 975 if self.name not in obj._filecache:
975 obj._filecache[self.name].obj = value # update cached copy 976 # we add an entry for the missing value because X in __dict__
977 # implies X in _filecache
978 ce = filecacheentry(self.join(obj, self.path), False)
979 obj._filecache[self.name] = ce
980 else:
981 ce = obj._filecache[self.name]
982
983 ce.obj = value # update cached copy
976 obj.__dict__[self.name] = value # update copy returned by obj.x 984 obj.__dict__[self.name] = value # update copy returned by obj.x
977 985
978 def __delete__(self, obj): 986 def __delete__(self, obj):
979 try: 987 try:
980 del obj.__dict__[self.name] 988 del obj.__dict__[self.name]