Mercurial > public > mercurial-scm > hg
comparison mercurial/manifest.py @ 29825:426d931e5db2
manifest: introduce manifestlog and manifestctx classes
This is the start of a large refactoring of the manifest class. It introduces
the new manifestlog and manifestctx classes which will represent the collection
of all manifests and individual instances, respectively.
Future patches will begin to convert usages of repo.manifest to
repo.manifestlog, adding the necessary functionality to manifestlog and instance
as they are needed.
author | Durham Goode <durham@fb.com> |
---|---|
date | Wed, 17 Aug 2016 13:25:13 -0700 |
parents | 58d4ecdc531e |
children | 93b44aa17691 |
comparison
equal
deleted
inserted
replaced
29824:58d4ecdc531e | 29825:426d931e5db2 |
---|---|
911 return self._fulltextcache | 911 return self._fulltextcache |
912 | 912 |
913 def clearcaches(self): | 913 def clearcaches(self): |
914 super(manifestrevlog, self).clearcaches() | 914 super(manifestrevlog, self).clearcaches() |
915 self._fulltextcache.clear() | 915 self._fulltextcache.clear() |
916 | |
917 class manifestlog(object): | |
918 """A collection class representing the collection of manifest snapshots | |
919 referenced by commits in the repository. | |
920 | |
921 In this situation, 'manifest' refers to the abstract concept of a snapshot | |
922 of the list of files in the given commit. Consumers of the output of this | |
923 class do not care about the implementation details of the actual manifests | |
924 they receive (i.e. tree or flat or lazily loaded, etc).""" | |
925 def __init__(self, opener, oldmanifest): | |
926 self._revlog = oldmanifest | |
927 | |
928 # We'll separate this into it's own cache once oldmanifest is no longer | |
929 # used | |
930 self._mancache = oldmanifest._mancache | |
931 | |
932 # _revlog is the same as _oldmanifest right now, but we eventually want | |
933 # to delete _oldmanifest while still allowing manifestlog to access the | |
934 # revlog specific apis. | |
935 self._oldmanifest = oldmanifest | |
936 | |
937 def __getitem__(self, node): | |
938 """Retrieves the manifest instance for the given node. Throws a KeyError | |
939 if not found. | |
940 """ | |
941 if (self._oldmanifest._treeondisk | |
942 or self._oldmanifest._treeinmem): | |
943 # TODO: come back and support tree manifests directly | |
944 return self._oldmanifest.read(node) | |
945 | |
946 if node == revlog.nullid: | |
947 return manifestdict() | |
948 if node in self._mancache: | |
949 cachemf = self._mancache[node] | |
950 # The old manifest may put non-ctx manifests in the cache, so skip | |
951 # those since they don't implement the full api. | |
952 if isinstance(cachemf, manifestctx): | |
953 return cachemf | |
954 | |
955 m = manifestctx(self._revlog, node) | |
956 self._mancache[node] = m | |
957 return m | |
958 | |
959 class manifestctx(manifestdict): | |
960 """A class representing a single revision of a manifest, including its | |
961 contents, its parent revs, and its linkrev. | |
962 """ | |
963 def __init__(self, revlog, node): | |
964 self._revlog = revlog | |
965 | |
966 self._node = node | |
967 self.p1, self.p2 = revlog.parents(node) | |
968 rev = revlog.rev(node) | |
969 self.linkrev = revlog.linkrev(rev) | |
970 | |
971 # This should eventually be made lazy loaded, so consumers can access | |
972 # the node/p1/linkrev data without having to parse the whole manifest. | |
973 data = revlog.revision(node) | |
974 arraytext = array.array('c', data) | |
975 revlog._fulltextcache[node] = arraytext | |
976 super(manifestctx, self).__init__(data) | |
977 | |
978 def node(self): | |
979 return self._node | |
916 | 980 |
917 class manifest(manifestrevlog): | 981 class manifest(manifestrevlog): |
918 def __init__(self, opener, dir='', dirlogcache=None): | 982 def __init__(self, opener, dir='', dirlogcache=None): |
919 '''The 'dir' and 'dirlogcache' arguments are for internal use by | 983 '''The 'dir' and 'dirlogcache' arguments are for internal use by |
920 manifest.manifest only. External users should create a root manifest | 984 manifest.manifest only. External users should create a root manifest |