Mercurial > public > mercurial-scm > hg
comparison mercurial/manifest.py @ 41962:07c80298b5a1
manifestcache: abstract the filename in a class attribute
This make the code clearer and simpler to update.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 15 Mar 2019 12:17:30 +0000 |
parents | c3522b015f81 |
children | d121823072b8 |
comparison
equal
deleted
inserted
replaced
41961:c3522b015f81 | 41962:07c80298b5a1 |
---|---|
1274 - 20 bytes node, 4 bytes length, <length> manifest data | 1274 - 20 bytes node, 4 bytes length, <length> manifest data |
1275 | 1275 |
1276 These are written in reverse cache order (oldest to newest). | 1276 These are written in reverse cache order (oldest to newest). |
1277 | 1277 |
1278 """ | 1278 """ |
1279 | |
1280 _file = 'manifestfulltextcache' | |
1281 | |
1279 def __init__(self, max): | 1282 def __init__(self, max): |
1280 super(manifestfulltextcache, self).__init__(max) | 1283 super(manifestfulltextcache, self).__init__(max) |
1281 self._dirty = False | 1284 self._dirty = False |
1282 self._read = False | 1285 self._read = False |
1283 self._opener = None | 1286 self._opener = None |
1285 def read(self): | 1288 def read(self): |
1286 if self._read or self._opener is None: | 1289 if self._read or self._opener is None: |
1287 return | 1290 return |
1288 | 1291 |
1289 try: | 1292 try: |
1290 with self._opener('manifestfulltextcache') as fp: | 1293 with self._opener(self._file) as fp: |
1291 set = super(manifestfulltextcache, self).__setitem__ | 1294 set = super(manifestfulltextcache, self).__setitem__ |
1292 # ignore trailing data, this is a cache, corruption is skipped | 1295 # ignore trailing data, this is a cache, corruption is skipped |
1293 while True: | 1296 while True: |
1294 node = fp.read(20) | 1297 node = fp.read(20) |
1295 if len(node) < 20: | 1298 if len(node) < 20: |
1311 | 1314 |
1312 def write(self): | 1315 def write(self): |
1313 if not self._dirty or self._opener is None: | 1316 if not self._dirty or self._opener is None: |
1314 return | 1317 return |
1315 # rotate backwards to the first used node | 1318 # rotate backwards to the first used node |
1316 with self._opener( | 1319 with self._opener(self._file, 'w', atomictemp=True, checkambig=True |
1317 'manifestfulltextcache', 'w', atomictemp=True, checkambig=True | |
1318 ) as fp: | 1320 ) as fp: |
1319 node = self._head.prev | 1321 node = self._head.prev |
1320 while True: | 1322 while True: |
1321 if node.key in self._cache: | 1323 if node.key in self._cache: |
1322 fp.write(node.key) | 1324 fp.write(node.key) |