Mercurial > hg
comparison mercurial/repository.py @ 39314:7f5e6d3e9032
manifest: proxy to revlog instance instead of inheriting
Previously, manifestrevlog inherited revlog.revlog and therefore
exposed all its APIs. This inevitably resulted in consumers calling
low-level revlog APIs.
As part of abstracting storage, we want to formalize the interface
for manifest storage. The revlog API is much too large to define as
the interface.
Like we did for filelog, this commit divorces the manifest class
from revlog so that we can standardize on a smaller API surface.
The way I went about this commit was I broke the inheritance, ran
tests, and added proxies until all tests passed. Like filelog, there
are a handful of attributes that don't belong on the interface.
And like filelog, we'll tease these out in the future.
As part of this, we formalize an interface for manifest storage and
add checks that manifestrevlog conforms to the interface.
Adding proxies will introduce some overhead due to extra attribute
lookups and function calls. On the mozilla-unified repository:
$ hg verify
before: real 627.220 secs (user 525.870+0.000 sys 18.800+0.000)
after: real 628.930 secs (user 532.050+0.000 sys 18.320+0.000)
$ hg serve (for a clone)
before: user 223.580+0.000 sys 14.270+0.000
after: user 227.720+0.000 sys 13.920+0.000
$ hg clone
before: user 506.390+0.000 sys 29.720+0.000
after: user 513.080+0.000 sys 28.280+0.000
There appears to be some overhead here. But it appears to be 1-2%.
I think that is an appropriate price to pay for storage abstraction,
which will eventually let us have much nicer things. If the overhead
is noticed in other operations (whose CPU time isn't likely dwarfed by
fulltext resolution) or if we want to cut down on the overhead, we
could dynamically build up a type whose methods are effectively
aliased to a revlog instance's. I'm inclined to punt on that problem
for now. We may have to do it for the changelog. At which point it
could be implemented in a generic way and ported to filelog and
manifestrevlog easily enough I would think.
.. api:: manifest.manifestrevlog no longer inherits from revlog
The manifestrevlog class now wraps a revlog instance instead of
inheriting from revlog. Various attributes and methods on instances
are no longer available.
Differential Revision: https://phab.mercurial-scm.org/D4386
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 27 Aug 2018 10:15:15 -0700 |
parents | 73cf21b2e8a6 |
children | 57c3864f3aad |
comparison
equal
deleted
inserted
replaced
39313:6f38284b23f4 | 39314:7f5e6d3e9032 |
---|---|
986 removed paths. | 986 removed paths. |
987 | 987 |
988 Returns the binary node of the created revision. | 988 Returns the binary node of the created revision. |
989 """ | 989 """ |
990 | 990 |
991 class imanifeststorage(interfaceutil.Interface): | |
992 """Storage interface for manifest data.""" | |
993 | |
994 index = interfaceutil.Attribute( | |
995 """An ``ifilerevisionssequence`` instance.""") | |
996 | |
997 indexfile = interfaceutil.Attribute( | |
998 """Path of revlog index file. | |
999 | |
1000 TODO this is revlog specific and should not be exposed. | |
1001 """) | |
1002 | |
1003 opener = interfaceutil.Attribute( | |
1004 """VFS opener to use to access underlying files used for storage. | |
1005 | |
1006 TODO this is revlog specific and should not be exposed. | |
1007 """) | |
1008 | |
1009 version = interfaceutil.Attribute( | |
1010 """Revlog version number. | |
1011 | |
1012 TODO this is revlog specific and should not be exposed. | |
1013 """) | |
1014 | |
1015 _generaldelta = interfaceutil.Attribute( | |
1016 """Whether generaldelta storage is being used. | |
1017 | |
1018 TODO this is revlog specific and should not be exposed. | |
1019 """) | |
1020 | |
1021 fulltextcache = interfaceutil.Attribute( | |
1022 """Dict with cache of fulltexts. | |
1023 | |
1024 TODO this doesn't feel appropriate for the storage interface. | |
1025 """) | |
1026 | |
1027 def __len__(): | |
1028 """Obtain the number of revisions stored for this manifest.""" | |
1029 | |
1030 def __iter__(): | |
1031 """Iterate over revision numbers for this manifest.""" | |
1032 | |
1033 def rev(node): | |
1034 """Obtain the revision number given a binary node. | |
1035 | |
1036 Raises ``error.LookupError`` if the node is not known. | |
1037 """ | |
1038 | |
1039 def node(rev): | |
1040 """Obtain the node value given a revision number. | |
1041 | |
1042 Raises ``error.LookupError`` if the revision is not known. | |
1043 """ | |
1044 | |
1045 def lookup(value): | |
1046 """Attempt to resolve a value to a node. | |
1047 | |
1048 Value can be a binary node, hex node, revision number, or a bytes | |
1049 that can be converted to an integer. | |
1050 | |
1051 Raises ``error.LookupError`` if a ndoe could not be resolved. | |
1052 | |
1053 TODO this is only used by debug* commands and can probably be deleted | |
1054 easily. | |
1055 """ | |
1056 | |
1057 def parents(node): | |
1058 """Returns a 2-tuple of parent nodes for a node. | |
1059 | |
1060 Values will be ``nullid`` if the parent is empty. | |
1061 """ | |
1062 | |
1063 def parentrevs(rev): | |
1064 """Like parents() but operates on revision numbers.""" | |
1065 | |
1066 def linkrev(rev): | |
1067 """Obtain the changeset revision number a revision is linked to.""" | |
1068 | |
1069 def revision(node, _df=None, raw=False): | |
1070 """Obtain fulltext data for a node.""" | |
1071 | |
1072 def revdiff(rev1, rev2): | |
1073 """Obtain a delta between two revision numbers. | |
1074 | |
1075 The returned data is the result of ``bdiff.bdiff()`` on the raw | |
1076 revision data. | |
1077 """ | |
1078 | |
1079 def cmp(node, fulltext): | |
1080 """Compare fulltext to another revision. | |
1081 | |
1082 Returns True if the fulltext is different from what is stored. | |
1083 """ | |
1084 | |
1085 def emitrevisiondeltas(requests): | |
1086 """Produce ``irevisiondelta`` from ``irevisiondeltarequest``s. | |
1087 | |
1088 See the documentation for ``ifiledata`` for more. | |
1089 """ | |
1090 | |
1091 def addgroup(deltas, linkmapper, transaction, addrevisioncb=None): | |
1092 """Process a series of deltas for storage. | |
1093 | |
1094 See the documentation in ``ifilemutation`` for more. | |
1095 """ | |
1096 | |
1097 def getstrippoint(minlink): | |
1098 """Find minimum revision that must be stripped to strip a linkrev. | |
1099 | |
1100 See the documentation in ``ifilemutation`` for more. | |
1101 """ | |
1102 | |
1103 def strip(minlink, transaction): | |
1104 """Remove storage of items starting at a linkrev. | |
1105 | |
1106 See the documentation in ``ifilemutation`` for more. | |
1107 """ | |
1108 | |
1109 def checksize(): | |
1110 """Obtain the expected sizes of backing files. | |
1111 | |
1112 TODO this is used by verify and it should not be part of the interface. | |
1113 """ | |
1114 | |
1115 def files(): | |
1116 """Obtain paths that are backing storage for this manifest. | |
1117 | |
1118 TODO this is used by verify and there should probably be a better API | |
1119 for this functionality. | |
1120 """ | |
1121 | |
1122 def deltaparent(rev): | |
1123 """Obtain the revision that a revision is delta'd against. | |
1124 | |
1125 TODO delta encoding is an implementation detail of storage and should | |
1126 not be exposed to the storage interface. | |
1127 """ | |
1128 | |
1129 def clone(tr, dest, **kwargs): | |
1130 """Clone this instance to another.""" | |
1131 | |
1132 def clearcaches(clear_persisted_data=False): | |
1133 """Clear any caches associated with this instance.""" | |
1134 | |
1135 def dirlog(d): | |
1136 """Obtain a manifest storage instance for a tree.""" | |
1137 | |
1138 def add(m, transaction, link, p1, p2, added, removed, readtree=None): | |
1139 """Add a revision to storage. | |
1140 | |
1141 ``m`` is an object conforming to ``imanifestdict``. | |
1142 | |
1143 ``link`` is the linkrev revision number. | |
1144 | |
1145 ``p1`` and ``p2`` are the parent revision numbers. | |
1146 | |
1147 ``added`` and ``removed`` are iterables of added and removed paths, | |
1148 respectively. | |
1149 """ | |
1150 | |
991 class imanifestlog(interfaceutil.Interface): | 1151 class imanifestlog(interfaceutil.Interface): |
992 """Interface representing a collection of manifest snapshots. | 1152 """Interface representing a collection of manifest snapshots. |
993 | 1153 |
994 Represents the root manifest in a repository. | 1154 Represents the root manifest in a repository. |
995 | 1155 |