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.
--- 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
--- a/mercurial/statichttprepo.py Wed Feb 15 23:44:10 2012 +0200
+++ b/mercurial/statichttprepo.py Wed Feb 15 20:02:35 2012 +0200
@@ -112,6 +112,7 @@
self.spath = self.store.path
self.sopener = self.store.opener
self.sjoin = self.store.join
+ self._filecache = {}
self.manifest = manifest.manifest(self.sopener)
self.changelog = changelog.changelog(self.sopener)
@@ -122,7 +123,6 @@
self.encodepats = None
self.decodepats = None
self.capabilities.difference_update(["pushkey"])
- self._filecache = {}
def url(self):
return self._url
--- a/tests/test-commandserver.py Wed Feb 15 23:44:10 2012 +0200
+++ b/tests/test-commandserver.py Wed Feb 15 20:02:35 2012 +0200
@@ -181,6 +181,13 @@
os.system('hg upd bm1 -q')
runcommand(server, ['bookmarks'])
+ runcommand(server, ['bookmarks', 'bm3'])
+ f = open('a', 'ab')
+ f.write('a\n')
+ f.close()
+ runcommand(server, ['commit', '-Amm'])
+ runcommand(server, ['bookmarks'])
+
def tagscache(server):
readchannel(server)
runcommand(server, ['id', '-t', '-r', '0'])
--- a/tests/test-commandserver.py.out Wed Feb 15 23:44:10 2012 +0200
+++ b/tests/test-commandserver.py.out Wed Feb 15 20:02:35 2012 +0200
@@ -114,6 +114,12 @@
runcommand bookmarks
* bm1 1:d3a0a68be6de
bm2 1:d3a0a68be6de
+ runcommand bookmarks bm3
+ runcommand commit -Amm
+ runcommand bookmarks
+ bm1 1:d3a0a68be6de
+ bm2 1:d3a0a68be6de
+ * bm3 2:aef17e88f5f0
testing tagscache:
@@ -125,6 +131,6 @@
testing setphase:
runcommand phase -r .
-2: draft
+3: draft
runcommand phase -r .
-2: public
+3: public