mercurial/manifest.py
changeset 29907 4fb4fc331699
parent 29888 8a84347b9907
child 29908 bb3281b3fcaa
equal deleted inserted replaced
29906:41491cf936f2 29907:4fb4fc331699
   944 
   944 
   945     def __getitem__(self, node):
   945     def __getitem__(self, node):
   946         """Retrieves the manifest instance for the given node. Throws a KeyError
   946         """Retrieves the manifest instance for the given node. Throws a KeyError
   947         if not found.
   947         if not found.
   948         """
   948         """
   949         if (self._oldmanifest._treeondisk
       
   950             or self._oldmanifest._treeinmem):
       
   951             # TODO: come back and support tree manifests directly
       
   952             return self._oldmanifest.read(node)
       
   953 
       
   954         if node == revlog.nullid:
       
   955             return manifestdict()
       
   956         if node in self._mancache:
   949         if node in self._mancache:
   957             cachemf = self._mancache[node]
   950             cachemf = self._mancache[node]
   958             # The old manifest may put non-ctx manifests in the cache, so skip
   951             # The old manifest may put non-ctx manifests in the cache, so skip
   959             # those since they don't implement the full api.
   952             # those since they don't implement the full api.
   960             if isinstance(cachemf, manifestctx):
   953             if (isinstance(cachemf, manifestctx) or
       
   954                 isinstance(cachemf, treemanifestctx)):
   961                 return cachemf
   955                 return cachemf
   962 
   956 
   963         m = manifestctx(self._revlog, node)
   957         if self._oldmanifest._treeinmem:
   964         self._mancache[node] = m
   958             m = treemanifestctx(self._revlog, '', node)
       
   959         else:
       
   960             m = manifestctx(self._revlog, node)
       
   961         if node != revlog.nullid:
       
   962             self._mancache[node] = m
   965         return m
   963         return m
   966 
   964 
   967 class manifestctx(manifestdict):
   965 class manifestctx(manifestdict):
   968     """A class representing a single revision of a manifest, including its
   966     """A class representing a single revision of a manifest, including its
   969     contents, its parent revs, and its linkrev.
   967     contents, its parent revs, and its linkrev.
   970     """
   968     """
   971     def __init__(self, revlog, node):
   969     def __init__(self, revlog, node):
   972         self._revlog = revlog
   970         self._revlog = revlog
   973 
   971 
   974         self._node = node
   972         self._node = node
   975         self.p1, self.p2 = revlog.parents(node)
   973 
   976         rev = revlog.rev(node)
   974         # TODO: We eventually want p1, p2, and linkrev exposed on this class,
   977         self.linkrev = revlog.linkrev(rev)
   975         # but let's add it later when something needs it and we can load it
       
   976         # lazily.
       
   977         #self.p1, self.p2 = revlog.parents(node)
       
   978         #rev = revlog.rev(node)
       
   979         #self.linkrev = revlog.linkrev(rev)
   978 
   980 
   979         # This should eventually be made lazy loaded, so consumers can access
   981         # This should eventually be made lazy loaded, so consumers can access
   980         # the node/p1/linkrev data without having to parse the whole manifest.
   982         # the node/p1/linkrev data without having to parse the whole manifest.
   981         data = revlog.revision(node)
   983         data = revlog.revision(node)
   982         arraytext = array.array('c', data)
   984         arraytext = array.array('c', data)
   983         revlog._fulltextcache[node] = arraytext
   985         revlog._fulltextcache[node] = arraytext
   984         super(manifestctx, self).__init__(data)
   986         super(manifestctx, self).__init__(data)
       
   987 
       
   988     def node(self):
       
   989         return self._node
       
   990 
       
   991 class treemanifestctx(treemanifest):
       
   992     def __init__(self, revlog, dir, node):
       
   993         revlog = revlog.dirlog(dir)
       
   994         self._revlog = revlog
       
   995         self._dir = dir
       
   996 
       
   997         self._node = node
       
   998 
       
   999         # TODO: Load p1/p2/linkrev lazily. They need to be lazily loaded so that
       
  1000         # we can instantiate treemanifestctx objects for directories we don't
       
  1001         # have on disk.
       
  1002         #self.p1, self.p2 = revlog.parents(node)
       
  1003         #rev = revlog.rev(node)
       
  1004         #self.linkrev = revlog.linkrev(rev)
       
  1005 
       
  1006         if revlog._treeondisk:
       
  1007             super(treemanifestctx, self).__init__(dir=dir)
       
  1008             def gettext():
       
  1009                 return revlog.revision(node)
       
  1010             def readsubtree(dir, subm):
       
  1011                 return revlog.dirlog(dir).read(subm)
       
  1012             self.read(gettext, readsubtree)
       
  1013             self.setnode(node)
       
  1014         else:
       
  1015             text = revlog.revision(node)
       
  1016             arraytext = array.array('c', text)
       
  1017             revlog.fulltextcache[node] = arraytext
       
  1018             super(treemanifestctx, self).__init__(dir=dir, text=text)
   985 
  1019 
   986     def node(self):
  1020     def node(self):
   987         return self._node
  1021         return self._node
   988 
  1022 
   989 class manifest(manifestrevlog):
  1023 class manifest(manifestrevlog):