comparison mercurial/manifest.py @ 30292:d4b340bf68c5

manifest: change manifestlog mancache to be directory based In the last patch we added a get() function that allows fetching directory level treemanifestctxs. It didn't handle caching at directory level though, so we need to change our mancache to support multiple directories.
author Durham Goode <durham@fb.com>
date Wed, 02 Nov 2016 17:10:47 -0700
parents dc21ea3323c4
children 78f3c7166f0d
comparison
equal deleted inserted replaced
30291:dc21ea3323c4 30292:d4b340bf68c5
1255 self._treeinmem = usetreemanifest 1255 self._treeinmem = usetreemanifest
1256 1256
1257 self._oldmanifest = repo._constructmanifest() 1257 self._oldmanifest = repo._constructmanifest()
1258 self._revlog = self._oldmanifest 1258 self._revlog = self._oldmanifest
1259 1259
1260 # A cache of the manifestctx or treemanifestctx for each directory
1261 self._dirmancache = {}
1262
1260 # We'll separate this into it's own cache once oldmanifest is no longer 1263 # We'll separate this into it's own cache once oldmanifest is no longer
1261 # used 1264 # used
1262 self._mancache = self._oldmanifest._mancache 1265 self._mancache = self._oldmanifest._mancache
1266 self._dirmancache[''] = self._mancache
1267
1268 # A future patch makes this use the same config value as the existing
1269 # mancache
1270 self.cachesize = 4
1263 1271
1264 def __getitem__(self, node): 1272 def __getitem__(self, node):
1265 """Retrieves the manifest instance for the given node. Throws a 1273 """Retrieves the manifest instance for the given node. Throws a
1266 LookupError if not found. 1274 LookupError if not found.
1267 """ 1275 """
1269 1277
1270 def get(self, dir, node): 1278 def get(self, dir, node):
1271 """Retrieves the manifest instance for the given node. Throws a 1279 """Retrieves the manifest instance for the given node. Throws a
1272 LookupError if not found. 1280 LookupError if not found.
1273 """ 1281 """
1282 if node in self._dirmancache.get(dir, ()):
1283 cachemf = self._dirmancache[dir][node]
1284 # The old manifest may put non-ctx manifests in the cache, so
1285 # skip those since they don't implement the full api.
1286 if (isinstance(cachemf, manifestctx) or
1287 isinstance(cachemf, treemanifestctx)):
1288 return cachemf
1289
1274 if dir: 1290 if dir:
1275 if self._revlog._treeondisk: 1291 if self._revlog._treeondisk:
1276 dirlog = self._revlog.dirlog(dir) 1292 dirlog = self._revlog.dirlog(dir)
1277 if node not in dirlog.nodemap: 1293 if node not in dirlog.nodemap:
1278 raise LookupError(node, dirlog.indexfile, 1294 raise LookupError(node, dirlog.indexfile,
1281 else: 1297 else:
1282 raise error.Abort( 1298 raise error.Abort(
1283 _("cannot ask for manifest directory '%s' in a flat " 1299 _("cannot ask for manifest directory '%s' in a flat "
1284 "manifest") % dir) 1300 "manifest") % dir)
1285 else: 1301 else:
1286 if node in self._mancache:
1287 cachemf = self._mancache[node]
1288 # The old manifest may put non-ctx manifests in the cache, so
1289 # skip those since they don't implement the full api.
1290 if (isinstance(cachemf, manifestctx) or
1291 isinstance(cachemf, treemanifestctx)):
1292 return cachemf
1293
1294 if node not in self._revlog.nodemap: 1302 if node not in self._revlog.nodemap:
1295 raise LookupError(node, self._revlog.indexfile, 1303 raise LookupError(node, self._revlog.indexfile,
1296 _('no node')) 1304 _('no node'))
1297 if self._treeinmem: 1305 if self._treeinmem:
1298 m = treemanifestctx(self._repo, '', node) 1306 m = treemanifestctx(self._repo, '', node)
1299 else: 1307 else:
1300 m = manifestctx(self._repo, node) 1308 m = manifestctx(self._repo, node)
1301 if node != revlog.nullid: 1309
1302 self._mancache[node] = m 1310 if node != revlog.nullid:
1311 mancache = self._dirmancache.get(dir)
1312 if not mancache:
1313 mancache = util.lrucachedict(self.cachesize)
1314 self._dirmancache[dir] = mancache
1315 mancache[node] = m
1303 return m 1316 return m
1304 1317
1305 def add(self, m, transaction, link, p1, p2, added, removed): 1318 def add(self, m, transaction, link, p1, p2, added, removed):
1306 return self._revlog.add(m, transaction, link, p1, p2, added, removed) 1319 return self._revlog.add(m, transaction, link, p1, p2, added, removed)
1307 1320