# HG changeset patch # User Pierre-Yves David # Date 1500591872 -7200 # Node ID e1b7ea48e2438bc936cc33988415c1513f9bb17f # Parent 723f5b505c48b2e055b8eeaa1d8890ed149efe4e 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. diff -r 723f5b505c48 -r e1b7ea48e243 hgext3rd/evolve/obscache.py --- 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())