changeset 2749:e1b7ea48e243

compat: use 'repo.cachevfs' when available In 4133c0b0fcd7 (core), the repository gained a new vfs dedicated to caches. We update the code to follow this new pattern.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 21 Jul 2017 01:04:32 +0200
parents 723f5b505c48
children bd3824d1b795
files hgext3rd/evolve/obscache.py
diffstat 1 files changed, 11 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/obscache.py	Sun Jul 16 11:11:06 2017 +0200
+++ b/hgext3rd/evolve/obscache.py	Fri Jul 21 01:04:32 2017 +0200
@@ -22,6 +22,7 @@
     pycompat,
     node,
     util,
+    vfs as vfsmod,
 )
 
 from mercurial.i18n import _
@@ -320,6 +321,12 @@
 
         return reset, revs, markers, (obssize, obskey)
 
+def getcachevfs(repo):
+    cachevfs = getattr(repo, 'cachevfs', None)
+    if cachevfs is None:
+        cachevfs = vfsmod.vfs(repo.vfs.join('cache'))
+        cachevfs.createmode = repo.store.createmode
+    return cachevfs
 
 class obscache(dualsourcecache):
     """cache the "does a rev" is the precursors of some obsmarkers data
@@ -355,7 +362,7 @@
         zero. That would be especially useful for the '.pending' overlay.
     """
 
-    _filepath = 'cache/evoext-obscache-00'
+    _filepath = 'evoext-obscache-00'
     _headerformat = '>q20sQQ20s'
 
     _cachename = 'evo-ext-obscache' # used for error message
@@ -363,8 +370,7 @@
     def __init__(self, repo):
         super(obscache, self).__init__()
         self._ondiskkey = None
-        self._vfs = repo.vfs
-        self._setdata(bytearray())
+        self._vfs = getcachevfs(repo)
 
     @util.propertycache
     def get(self):
@@ -445,7 +451,7 @@
         if self._cachekey is None or self._cachekey == self._ondiskkey:
             return
 
-        cachefile = repo.vfs(self._filepath, 'w', atomictemp=True)
+        cachefile = self._vfs(self._filepath, 'w', atomictemp=True)
         headerdata = struct.pack(self._headerformat, *self._cachekey)
         cachefile.write(headerdata)
         cachefile.write(self._data)
@@ -455,7 +461,7 @@
         """load data from disk"""
         assert repo.filtername is None
 
-        data = repo.vfs.tryread(self._filepath)
+        data = self._vfs.tryread(self._filepath)
         if not data:
             self._cachekey = self.emptykey
             self._setdata(bytearray())