changeset 16198:fa8488565afd stable

filecache: refactor path join logic to a function New users of filecache use different names for the function used to compute the runtime path of the cached file. Users should subclass filecache and provide their own version of this function to call the appropriate join function on 'obj' (an instance of the class that its member function was decorated).
author Idan Kamara <idankk86@gmail.com>
date Thu, 01 Mar 2012 17:39:58 +0200
parents 8ae7626d8bf1
children 8181bd808dc5
files mercurial/localrepo.py mercurial/scmutil.py
diffstat 2 files changed, 19 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/localrepo.py	Wed Feb 29 14:24:57 2012 +0100
+++ b/mercurial/localrepo.py	Thu Mar 01 17:39:58 2012 +0200
@@ -19,6 +19,11 @@
 propertycache = util.propertycache
 filecache = scmutil.filecache
 
+class storecache(filecache):
+    """filecache for files in the store"""
+    def join(self, obj, fname):
+        return obj.sjoin(fname)
+
 class localrepository(repo.repository):
     capabilities = set(('lookup', 'changegroupsubset', 'branchmap', 'pushkey',
                         'known', 'getbundle'))
@@ -176,7 +181,7 @@
     def _writebookmarks(self, marks):
       bookmarks.write(self)
 
-    @filecache('phaseroots', True)
+    @storecache('phaseroots')
     def _phaseroots(self):
         self._dirtyphases = False
         phaseroots = phases.readroots(self)
@@ -195,7 +200,7 @@
                     cache[rev] = phase
         return cache
 
-    @filecache('00changelog.i', True)
+    @storecache('00changelog.i')
     def changelog(self):
         c = changelog.changelog(self.sopener)
         if 'HG_PENDING' in os.environ:
@@ -204,7 +209,7 @@
                 c.readpending('00changelog.i.a')
         return c
 
-    @filecache('00manifest.i', True)
+    @storecache('00manifest.i')
     def manifest(self):
         return manifest.manifest(self.sopener)
 
--- a/mercurial/scmutil.py	Wed Feb 29 14:24:57 2012 +0100
+++ b/mercurial/scmutil.py	Thu Mar 01 17:39:58 2012 +0200
@@ -793,9 +793,17 @@
     to tell us if a file has been replaced. If it can't, we fallback to
     recreating the object on every call (essentially the same behaviour as
     propertycache).'''
-    def __init__(self, path, instore=False):
+    def __init__(self, path):
         self.path = path
-        self.instore = instore
+
+    def join(self, obj, fname):
+        """Used to compute the runtime path of the cached file.
+
+        Users should subclass filecache and provide their own version of this
+        function to call the appropriate join function on 'obj' (an instance
+        of the class that its member function was decorated).
+        """
+        return obj.join(fname)
 
     def __call__(self, func):
         self.func = func
@@ -813,7 +821,7 @@
             if entry.changed():
                 entry.obj = self.func(obj)
         else:
-            path = self.instore and obj.sjoin(self.path) or obj.join(self.path)
+            path = self.join(obj, self.path)
 
             # We stat -before- creating the object so our cache doesn't lie if
             # a writer modified between the time we read and stat