comparison mercurial/manifest.py @ 51777:a891347058e7

manifest: introduce a `read_delta_parents` method This new method have a clearer semantic and can be used by code that need this semantic. This should avoid bugs, allow for more targeted optimisation, and provide a clearer API. Users will be updated in subsequent changesets. This is also part of the wider effort to clarify and fix this API. one more method coming.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 01 Aug 2024 13:10:09 +0200
parents e1fd715df257
children bcb825bf0c5e
comparison
equal deleted inserted replaced
51776:852bd109dd55 51777:a891347058e7
2281 deltaparent, 2281 deltaparent,
2282 manifestdict(store.nodeconstants.nodelen, d), 2282 manifestdict(store.nodeconstants.nodelen, d),
2283 ) 2283 )
2284 return (None, self.read()) 2284 return (None, self.read())
2285 2285
2286 def read_delta_parents(
2287 self,
2288 *,
2289 shallow: bool = False,
2290 exact: bool = True,
2291 ) -> ManifestDict:
2292 """see `interface.imanifestrevisionbase` documentations"""
2293 store = self._storage()
2294 r = store.rev(self._node)
2295 deltaparent = store.deltaparent(r)
2296 parents = [p for p in store.parentrevs(r) if p is not nullrev]
2297 if not exact and deltaparent in parents:
2298 d = mdiff.patchtext(store.revdiff(store.deltaparent(r), r))
2299 return manifestdict(store.nodeconstants.nodelen, d)
2300 elif not exact or len(parents) == 0:
2301 return self.read()
2302 elif len(parents) == 1:
2303 p = parents[0]
2304 d = mdiff.patchtext(store.revdiff(p, r))
2305 return manifestdict(store.nodeconstants.nodelen, d)
2306 else:
2307 p1, p2 = parents
2308 d1 = mdiff.patchtext(store.revdiff(p1, r))
2309 d2 = mdiff.patchtext(store.revdiff(p2, r))
2310 d1 = manifestdict(store.nodeconstants.nodelen, d1)
2311 d2 = manifestdict(store.nodeconstants.nodelen, d2)
2312 md = manifestdict(store.nodeconstants.nodelen)
2313 for f, new_node, new_flag in d1.iterentries():
2314 if f not in d2:
2315 continue
2316 if new_node is not None:
2317 md.set(f, new_node, new_flag)
2318 return md
2319
2286 def find(self, key: bytes) -> Tuple[bytes, bytes]: 2320 def find(self, key: bytes) -> Tuple[bytes, bytes]:
2287 return self.read().find(key) 2321 return self.read().find(key)
2288 2322
2289 2323
2290 manifestctx = interfaceutil.implementer(repository.imanifestrevisionstored)( 2324 manifestctx = interfaceutil.implementer(repository.imanifestrevisionstored)(
2484 md[f] = n1 2518 md[f] = n1
2485 if fl1: 2519 if fl1:
2486 md.setflag(f, fl1) 2520 md.setflag(f, fl1)
2487 return md 2521 return md
2488 2522
2523 def read_delta_parents(
2524 self,
2525 *,
2526 shallow: bool = False,
2527 exact: bool = True,
2528 ) -> AnyManifestDict:
2529 """see `interface.imanifestrevisionbase` documentations"""
2530 store = self._storage()
2531 r = store.rev(self._node)
2532 parents = [p for p in store.parentrevs(r) if p is not nullrev]
2533 if not exact:
2534 return self.read_any_fast_delta(parents, shallow=shallow)[1]
2535 elif len(parents) == 0:
2536 if shallow:
2537 d = store.revision(self._node)
2538 return manifestdict(store.nodeconstants.nodelen, d)
2539 else:
2540 return self.read()
2541 elif len(parents) == 1:
2542 p = parents[0]
2543 if shallow:
2544 d = mdiff.patchtext(store.revdiff(p, r))
2545 return manifestdict(store.nodeconstants.nodelen, d)
2546 else:
2547 return self._read_storage_slow_delta(base=p)
2548 else:
2549 p1, p2 = parents
2550 if shallow:
2551 d1 = mdiff.patchtext(store.revdiff(p1, r))
2552 d2 = mdiff.patchtext(store.revdiff(p2, r))
2553 d1 = manifestdict(store.nodeconstants.nodelen, d1)
2554 d2 = manifestdict(store.nodeconstants.nodelen, d2)
2555 md = manifestdict(store.nodeconstants.nodelen)
2556 for f, new_node, new_flag in d1.iterentries():
2557 if f not in d2:
2558 continue
2559 if new_node is not None:
2560 md.set(f, new_node, new_flag)
2561 return md
2562 else:
2563 m1 = self._manifestlog.get(self._dir, store.node(p1)).read()
2564 m2 = self._manifestlog.get(self._dir, store.node(p2)).read()
2565 mc = self.read()
2566 d1 = m1.diff(mc)
2567 d2 = m2.diff(mc)
2568 md = treemanifest(
2569 self._manifestlog.nodeconstants,
2570 dir=self._dir,
2571 )
2572 for f, new_node, new_flag in d1.iterentries():
2573 if f not in d2:
2574 continue
2575 if new_node is not None:
2576 md.set(f, new_node, new_flag)
2577 return md
2578
2489 def readfast(self, shallow=False) -> AnyManifestDict: 2579 def readfast(self, shallow=False) -> AnyManifestDict:
2490 """Calls either readdelta or read, based on which would be less work. 2580 """Calls either readdelta or read, based on which would be less work.
2491 readdelta is called if the delta is against the p1, and therefore can be 2581 readdelta is called if the delta is against the p1, and therefore can be
2492 read quickly. 2582 read quickly.
2493 2583