comparison mercurial/manifest.py @ 30291:dc21ea3323c4

manifest: add manifestlog.get to obtain subdirectory instances Previously manifestlog only allowed obtaining root level manifests. Future patches will need direct access to subdirectory manifests as part of changegroup creation, so let's add a get() function that knows how to deal with subdirectories.
author Durham Goode <durham@fb.com>
date Wed, 02 Nov 2016 17:24:06 -0700
parents 1a0c1ad57833
children d4b340bf68c5
comparison
equal deleted inserted replaced
30290:1a0c1ad57833 30291:dc21ea3323c4
1263 1263
1264 def __getitem__(self, node): 1264 def __getitem__(self, node):
1265 """Retrieves the manifest instance for the given node. Throws a 1265 """Retrieves the manifest instance for the given node. Throws a
1266 LookupError if not found. 1266 LookupError if not found.
1267 """ 1267 """
1268 if node in self._mancache: 1268 return self.get('', node)
1269 cachemf = self._mancache[node] 1269
1270 # The old manifest may put non-ctx manifests in the cache, so skip 1270 def get(self, dir, node):
1271 # those since they don't implement the full api. 1271 """Retrieves the manifest instance for the given node. Throws a
1272 if (isinstance(cachemf, manifestctx) or 1272 LookupError if not found.
1273 isinstance(cachemf, treemanifestctx)): 1273 """
1274 return cachemf 1274 if dir:
1275 1275 if self._revlog._treeondisk:
1276 if node not in self._revlog.nodemap: 1276 dirlog = self._revlog.dirlog(dir)
1277 raise LookupError(node, self._revlog.indexfile, 1277 if node not in dirlog.nodemap:
1278 _('no node')) 1278 raise LookupError(node, dirlog.indexfile,
1279 if self._treeinmem: 1279 _('no node'))
1280 m = treemanifestctx(self._repo, '', node) 1280 m = treemanifestctx(self._repo, dir, node)
1281 else: 1281 else:
1282 m = manifestctx(self._repo, node) 1282 raise error.Abort(
1283 if node != revlog.nullid: 1283 _("cannot ask for manifest directory '%s' in a flat "
1284 self._mancache[node] = m 1284 "manifest") % dir)
1285 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:
1295 raise LookupError(node, self._revlog.indexfile,
1296 _('no node'))
1297 if self._treeinmem:
1298 m = treemanifestctx(self._repo, '', node)
1299 else:
1300 m = manifestctx(self._repo, node)
1301 if node != revlog.nullid:
1302 self._mancache[node] = m
1285 return m 1303 return m
1286 1304
1287 def add(self, m, transaction, link, p1, p2, added, removed): 1305 def add(self, m, transaction, link, p1, p2, added, removed):
1288 return self._revlog.add(m, transaction, link, p1, p2, added, removed) 1306 return self._revlog.add(m, transaction, link, p1, p2, added, removed)
1289 1307