[PATCH STABLE] scmutil: update cached copy when filecached attribute is assigned (issue3263)

Idan Kamara idankk86 at gmail.com
Wed Feb 15 18:02:55 UTC 2012


# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1329328955 -7200
# Branch stable
# Node ID 985642ce5424c8a3096c15d6cf348805a4c9d4cc
# Parent  7e5a281a082cdbff4ae9553e01b5ff36dc2c11ee
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.

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -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
diff --git a/mercurial/statichttprepo.py b/mercurial/statichttprepo.py
--- a/mercurial/statichttprepo.py
+++ b/mercurial/statichttprepo.py
@@ -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
diff --git a/tests/test-commandserver.py b/tests/test-commandserver.py
--- a/tests/test-commandserver.py
+++ b/tests/test-commandserver.py
@@ -179,6 +179,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'])
diff --git a/tests/test-commandserver.py.out b/tests/test-commandserver.py.out
--- a/tests/test-commandserver.py.out
+++ b/tests/test-commandserver.py.out
@@ -111,6 +111,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:
 
@@ -122,6 +128,6 @@
 testing setphase:
 
  runcommand phase -r .
-2: draft
+3: draft
  runcommand phase -r .
-2: public
+3: public



More information about the Mercurial-devel mailing list