comparison mercurial/manifest.py @ 52063:35400ce47b64

manifest: drop the CamelCase name for `manifest.manifestdict` See 61557734c0ae for the reasoning.
author Matt Harbison <matt_harbison@yahoo.com>
date Wed, 23 Oct 2024 16:30:23 -0400
parents 5e79783d4bc7
children c392d57e8a06
comparison
equal deleted inserted replaced
52062:2876d077a796 52063:35400ce47b64
502 _lazymanifest = parsers.lazymanifest 502 _lazymanifest = parsers.lazymanifest
503 except AttributeError: 503 except AttributeError:
504 _lazymanifest = _LazyManifest 504 _lazymanifest = _LazyManifest
505 505
506 506
507 class ManifestDict: 507 class manifestdict: # (repository.imanifestdict)
508 def __init__(self, nodelen: int, data: ByteString = b''): 508 def __init__(self, nodelen: int, data: ByteString = b''):
509 self._nodelen = nodelen 509 self._nodelen = nodelen
510 self._lm = _lazymanifest(nodelen, data) 510 self._lm = _lazymanifest(nodelen, data)
511 511
512 def __getitem__(self, key: bytes) -> bytes: 512 def __getitem__(self, key: bytes) -> bytes:
610 610
611 for fn in sorted(fset): 611 for fn in sorted(fset):
612 if not self.hasdir(fn): 612 if not self.hasdir(fn):
613 match.bad(fn, None) 613 match.bad(fn, None)
614 614
615 def _matches(self, match: matchmod.basematcher) -> 'ManifestDict': 615 def _matches(self, match: matchmod.basematcher) -> 'manifestdict':
616 '''generate a new manifest filtered by the match argument''' 616 '''generate a new manifest filtered by the match argument'''
617 if match.always(): 617 if match.always():
618 return self.copy() 618 return self.copy()
619 619
620 if self._filesfastpath(match): 620 if self._filesfastpath(match):
629 m._lm = self._lm.filtercopy(match) 629 m._lm = self._lm.filtercopy(match)
630 return m 630 return m
631 631
632 def diff( 632 def diff(
633 self, 633 self,
634 m2: 'ManifestDict', 634 m2: 'manifestdict',
635 match: Optional[matchmod.basematcher] = None, 635 match: Optional[matchmod.basematcher] = None,
636 clean: bool = False, 636 clean: bool = False,
637 ) -> Dict[ 637 ) -> Dict[
638 bytes, 638 bytes,
639 Optional[ 639 Optional[
675 try: 675 try:
676 return self._lm[key][1] 676 return self._lm[key][1]
677 except KeyError: 677 except KeyError:
678 return b'' 678 return b''
679 679
680 def copy(self) -> 'ManifestDict': 680 def copy(self) -> 'manifestdict':
681 c = manifestdict(self._nodelen) 681 c = manifestdict(self._nodelen)
682 c._lm = self._lm.copy() 682 c._lm = self._lm.copy()
683 return c 683 return c
684 684
685 def items(self) -> Iterator[Tuple[bytes, bytes]]: 685 def items(self) -> Iterator[Tuple[bytes, bytes]]:
751 ) 751 )
752 752
753 return arraytext, deltatext 753 return arraytext, deltatext
754 754
755 755
756 manifestdict = interfaceutil.implementer(repository.imanifestdict)(ManifestDict)
757
758 if typing.TYPE_CHECKING:
759 manifestdict = ManifestDict
760
761
762 def _msearch( 756 def _msearch(
763 m: ByteString, s: bytes, lo: int = 0, hi: Optional[int] = None 757 m: ByteString, s: bytes, lo: int = 0, hi: Optional[int] = None
764 ) -> Tuple[int, int]: 758 ) -> Tuple[int, int]:
765 """return a tuple (start, end) that says where to find s within m. 759 """return a tuple (start, end) that says where to find s within m.
766 760
2063 2057
2064 if typing.TYPE_CHECKING: 2058 if typing.TYPE_CHECKING:
2065 manifestrevlog = ManifestRevlog 2059 manifestrevlog = ManifestRevlog
2066 2060
2067 AnyManifestCtx = Union['ManifestCtx', 'TreeManifestCtx'] 2061 AnyManifestCtx = Union['ManifestCtx', 'TreeManifestCtx']
2068 AnyManifestDict = Union[ManifestDict, TreeManifest] 2062 AnyManifestDict = Union[manifestdict, TreeManifest]
2069 2063
2070 2064
2071 class ManifestLog: 2065 class ManifestLog:
2072 """A collection class representing the collection of manifest snapshots 2066 """A collection class representing the collection of manifest snapshots
2073 referenced by commits in the repository. 2067 referenced by commits in the repository.
2177 if typing.TYPE_CHECKING: 2171 if typing.TYPE_CHECKING:
2178 manifestlog = ManifestLog 2172 manifestlog = ManifestLog
2179 2173
2180 2174
2181 class MemManifestCtx: 2175 class MemManifestCtx:
2182 _manifestdict: ManifestDict 2176 _manifestdict: manifestdict
2183 2177
2184 def __init__(self, manifestlog): 2178 def __init__(self, manifestlog):
2185 self._manifestlog = manifestlog 2179 self._manifestlog = manifestlog
2186 self._manifestdict = manifestdict(manifestlog.nodeconstants.nodelen) 2180 self._manifestdict = manifestdict(manifestlog.nodeconstants.nodelen)
2187 2181
2191 def copy(self) -> 'MemManifestCtx': 2185 def copy(self) -> 'MemManifestCtx':
2192 memmf = memmanifestctx(self._manifestlog) 2186 memmf = memmanifestctx(self._manifestlog)
2193 memmf._manifestdict = self.read().copy() 2187 memmf._manifestdict = self.read().copy()
2194 return memmf 2188 return memmf
2195 2189
2196 def read(self) -> 'ManifestDict': 2190 def read(self) -> 'manifestdict':
2197 return self._manifestdict 2191 return self._manifestdict
2198 2192
2199 def write(self, transaction, link, p1, p2, added, removed, match=None): 2193 def write(self, transaction, link, p1, p2, added, removed, match=None):
2200 return self._storage().add( 2194 return self._storage().add(
2201 self._manifestdict, 2195 self._manifestdict,
2220 class ManifestCtx: 2214 class ManifestCtx:
2221 """A class representing a single revision of a manifest, including its 2215 """A class representing a single revision of a manifest, including its
2222 contents, its parent revs, and its linkrev. 2216 contents, its parent revs, and its linkrev.
2223 """ 2217 """
2224 2218
2225 _data: Optional[ManifestDict] 2219 _data: Optional[manifestdict]
2226 2220
2227 def __init__(self, manifestlog, node): 2221 def __init__(self, manifestlog, node):
2228 self._manifestlog = manifestlog 2222 self._manifestlog = manifestlog
2229 self._data = None 2223 self._data = None
2230 2224
2250 2244
2251 @propertycache 2245 @propertycache
2252 def parents(self) -> Tuple[bytes, bytes]: 2246 def parents(self) -> Tuple[bytes, bytes]:
2253 return self._storage().parents(self._node) 2247 return self._storage().parents(self._node)
2254 2248
2255 def read(self) -> 'ManifestDict': 2249 def read(self) -> 'manifestdict':
2256 if self._data is None: 2250 if self._data is None:
2257 nc = self._manifestlog.nodeconstants 2251 nc = self._manifestlog.nodeconstants
2258 if self._node == nc.nullid: 2252 if self._node == nc.nullid:
2259 self._data = manifestdict(nc.nodelen) 2253 self._data = manifestdict(nc.nodelen)
2260 else: 2254 else:
2266 arraytext = bytearray(text) 2260 arraytext = bytearray(text)
2267 store.fulltextcache[self._node] = arraytext 2261 store.fulltextcache[self._node] = arraytext
2268 self._data = manifestdict(nc.nodelen, text) 2262 self._data = manifestdict(nc.nodelen, text)
2269 return self._data 2263 return self._data
2270 2264
2271 def readfast(self, shallow: bool = False) -> 'ManifestDict': 2265 def readfast(self, shallow: bool = False) -> 'manifestdict':
2272 """Calls either readdelta or read, based on which would be less work. 2266 """Calls either readdelta or read, based on which would be less work.
2273 readdelta is called if the delta is against the p1, and therefore can be 2267 readdelta is called if the delta is against the p1, and therefore can be
2274 read quickly. 2268 read quickly.
2275 2269
2276 If `shallow` is True, nothing changes since this is a flat manifest. 2270 If `shallow` is True, nothing changes since this is a flat manifest.
2285 deltaparent = store.deltaparent(r) 2279 deltaparent = store.deltaparent(r)
2286 if deltaparent != nullrev and deltaparent in store.parentrevs(r): 2280 if deltaparent != nullrev and deltaparent in store.parentrevs(r):
2287 return self.readdelta() 2281 return self.readdelta()
2288 return self.read() 2282 return self.read()
2289 2283
2290 def readdelta(self, shallow: bool = False) -> 'ManifestDict': 2284 def readdelta(self, shallow: bool = False) -> 'manifestdict':
2291 """Returns a manifest containing just the entries that are present 2285 """Returns a manifest containing just the entries that are present
2292 in this manifest, but not in its p1 manifest. This is efficient to read 2286 in this manifest, but not in its p1 manifest. This is efficient to read
2293 if the revlog delta is already p1. 2287 if the revlog delta is already p1.
2294 2288
2295 Changing the value of `shallow` has no effect on flat manifests. 2289 Changing the value of `shallow` has no effect on flat manifests.
2307 def read_any_fast_delta( 2301 def read_any_fast_delta(
2308 self, 2302 self,
2309 valid_bases: Optional[Collection[int]] = None, 2303 valid_bases: Optional[Collection[int]] = None,
2310 *, 2304 *,
2311 shallow: bool = False, 2305 shallow: bool = False,
2312 ) -> Tuple[Optional[int], ManifestDict]: 2306 ) -> Tuple[Optional[int], manifestdict]:
2313 """see `imanifestrevisionstored` documentation""" 2307 """see `imanifestrevisionstored` documentation"""
2314 store = self._storage() 2308 store = self._storage()
2315 r = store.rev(self._node) 2309 r = store.rev(self._node)
2316 deltaparent = store.deltaparent(r) 2310 deltaparent = store.deltaparent(r)
2317 if valid_bases is None: 2311 if valid_bases is None:
2328 def read_delta_parents( 2322 def read_delta_parents(
2329 self, 2323 self,
2330 *, 2324 *,
2331 shallow: bool = False, 2325 shallow: bool = False,
2332 exact: bool = True, 2326 exact: bool = True,
2333 ) -> ManifestDict: 2327 ) -> manifestdict:
2334 """see `interface.imanifestrevisionbase` documentations""" 2328 """see `interface.imanifestrevisionbase` documentations"""
2335 store = self._storage() 2329 store = self._storage()
2336 r = store.rev(self._node) 2330 r = store.rev(self._node)
2337 deltaparent = store.deltaparent(r) 2331 deltaparent = store.deltaparent(r)
2338 parents = [p for p in store.parentrevs(r) if p is not nullrev] 2332 parents = [p for p in store.parentrevs(r) if p is not nullrev]
2357 continue 2351 continue
2358 if new_node is not None: 2352 if new_node is not None:
2359 md.set(f, new_node, new_flag) 2353 md.set(f, new_node, new_flag)
2360 return md 2354 return md
2361 2355
2362 def read_delta_new_entries(self, *, shallow=False) -> ManifestDict: 2356 def read_delta_new_entries(self, *, shallow=False) -> manifestdict:
2363 """see `interface.imanifestrevisionbase` documentations""" 2357 """see `interface.imanifestrevisionbase` documentations"""
2364 # If we are using narrow, returning a delta against an arbitrary 2358 # If we are using narrow, returning a delta against an arbitrary
2365 # changeset might return file outside the narrowspec. This can create 2359 # changeset might return file outside the narrowspec. This can create
2366 # issue when running validation server side with strict security as 2360 # issue when running validation server side with strict security as
2367 # push from low priviledge usage might be seen as adding new revision 2361 # push from low priviledge usage might be seen as adding new revision
2569 best_base = max(parents) 2563 best_base = max(parents)
2570 else: 2564 else:
2571 best_base = max(valid_bases) 2565 best_base = max(valid_bases)
2572 return (None, self._read_storage_slow_delta(base=best_base)) 2566 return (None, self._read_storage_slow_delta(base=best_base))
2573 2567
2574 def _read_storage_delta_shallow(self) -> ManifestDict: 2568 def _read_storage_delta_shallow(self) -> manifestdict:
2575 store = self._storage() 2569 store = self._storage()
2576 r = store.rev(self._node) 2570 r = store.rev(self._node)
2577 d = mdiff.patchtext(store.revdiff(store.deltaparent(r), r)) 2571 d = mdiff.patchtext(store.revdiff(store.deltaparent(r), r))
2578 return manifestdict(store.nodeconstants.nodelen, d) 2572 return manifestdict(store.nodeconstants.nodelen, d)
2579 2573