Mercurial > hg-stable
comparison mercurial/revlog.py @ 51101:be56d322ee89
revlog: move the `rawtext` method on the inner object
This is one of the current core goal of the inner object: having a "simple" API
for some of the core revlog action, like getting a raw text, with the inner
object able to do that part internally, on its own.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 19 Oct 2023 03:52:31 +0200 |
parents | 8ec2de9c6770 |
children | 49d75cc12b8f |
comparison
equal
deleted
inserted
replaced
51100:8ec2de9c6770 | 51101:be56d322ee89 |
---|---|
898 msg %= comp_mode | 898 msg %= comp_mode |
899 raise error.RevlogError(msg) | 899 raise error.RevlogError(msg) |
900 | 900 |
901 return l | 901 return l |
902 | 902 |
903 def raw_text(self, node, rev): | |
904 """return the possibly unvalidated rawtext for a revision | |
905 | |
906 returns (rev, rawtext, validated) | |
907 """ | |
908 | |
909 # revision in the cache (could be useful to apply delta) | |
910 cachedrev = None | |
911 # An intermediate text to apply deltas to | |
912 basetext = None | |
913 | |
914 # Check if we have the entry in cache | |
915 # The cache entry looks like (node, rev, rawtext) | |
916 if self._revisioncache: | |
917 cachedrev = self._revisioncache[1] | |
918 | |
919 chain, stopped = self._deltachain(rev, stoprev=cachedrev) | |
920 if stopped: | |
921 basetext = self._revisioncache[2] | |
922 | |
923 # drop cache to save memory, the caller is expected to | |
924 # update self._inner._revisioncache after validating the text | |
925 self._revisioncache = None | |
926 | |
927 targetsize = None | |
928 rawsize = self.index[rev][2] | |
929 if 0 <= rawsize: | |
930 targetsize = 4 * rawsize | |
931 | |
932 bins = self._chunks(chain, targetsize=targetsize) | |
933 if basetext is None: | |
934 basetext = bytes(bins[0]) | |
935 bins = bins[1:] | |
936 | |
937 rawtext = mdiff.patches(basetext, bins) | |
938 del basetext # let us have a chance to free memory early | |
939 return (rev, rawtext, False) | |
940 | |
903 | 941 |
904 class revlog: | 942 class revlog: |
905 """ | 943 """ |
906 the underlying revision storage object | 944 the underlying revision storage object |
907 | 945 |
2529 rev = nodeorrev | 2567 rev = nodeorrev |
2530 else: | 2568 else: |
2531 rev = self.rev(nodeorrev) | 2569 rev = self.rev(nodeorrev) |
2532 return self._sidedata(rev) | 2570 return self._sidedata(rev) |
2533 | 2571 |
2572 def _rawtext(self, node, rev): | |
2573 """return the possibly unvalidated rawtext for a revision | |
2574 | |
2575 returns (rev, rawtext, validated) | |
2576 """ | |
2577 # Check if we have the entry in cache | |
2578 # The cache entry looks like (node, rev, rawtext) | |
2579 if self._inner._revisioncache: | |
2580 if self._inner._revisioncache[0] == node: | |
2581 return (rev, self._inner._revisioncache[2], True) | |
2582 | |
2583 if rev is None: | |
2584 rev = self.rev(node) | |
2585 | |
2586 return self._inner.raw_text(node, rev) | |
2587 | |
2534 def _revisiondata(self, nodeorrev, raw=False): | 2588 def _revisiondata(self, nodeorrev, raw=False): |
2535 # deal with <nodeorrev> argument type | 2589 # deal with <nodeorrev> argument type |
2536 if isinstance(nodeorrev, int): | 2590 if isinstance(nodeorrev, int): |
2537 rev = nodeorrev | 2591 rev = nodeorrev |
2538 node = self.node(rev) | 2592 node = self.node(rev) |
2572 self.checkhash(text, node, rev=rev) | 2626 self.checkhash(text, node, rev=rev) |
2573 if not validated: | 2627 if not validated: |
2574 self._inner._revisioncache = (node, rev, rawtext) | 2628 self._inner._revisioncache = (node, rev, rawtext) |
2575 | 2629 |
2576 return text | 2630 return text |
2577 | |
2578 def _rawtext(self, node, rev): | |
2579 """return the possibly unvalidated rawtext for a revision | |
2580 | |
2581 returns (rev, rawtext, validated) | |
2582 """ | |
2583 | |
2584 # revision in the cache (could be useful to apply delta) | |
2585 cachedrev = None | |
2586 # An intermediate text to apply deltas to | |
2587 basetext = None | |
2588 | |
2589 # Check if we have the entry in cache | |
2590 # The cache entry looks like (node, rev, rawtext) | |
2591 if self._inner._revisioncache: | |
2592 if self._inner._revisioncache[0] == node: | |
2593 return (rev, self._inner._revisioncache[2], True) | |
2594 cachedrev = self._inner._revisioncache[1] | |
2595 | |
2596 if rev is None: | |
2597 rev = self.rev(node) | |
2598 | |
2599 chain, stopped = self._inner._deltachain(rev, stoprev=cachedrev) | |
2600 if stopped: | |
2601 basetext = self._inner._revisioncache[2] | |
2602 | |
2603 # drop cache to save memory, the caller is expected to | |
2604 # update self._inner._revisioncache after validating the text | |
2605 self._inner._revisioncache = None | |
2606 | |
2607 targetsize = None | |
2608 rawsize = self.index[rev][2] | |
2609 if 0 <= rawsize: | |
2610 targetsize = 4 * rawsize | |
2611 | |
2612 bins = self._inner._chunks(chain, targetsize=targetsize) | |
2613 if basetext is None: | |
2614 basetext = bytes(bins[0]) | |
2615 bins = bins[1:] | |
2616 | |
2617 rawtext = mdiff.patches(basetext, bins) | |
2618 del basetext # let us have a chance to free memory early | |
2619 return (rev, rawtext, False) | |
2620 | 2631 |
2621 def _sidedata(self, rev): | 2632 def _sidedata(self, rev): |
2622 """Return the sidedata for a given revision number.""" | 2633 """Return the sidedata for a given revision number.""" |
2623 index_entry = self.index[rev] | 2634 index_entry = self.index[rev] |
2624 sidedata_offset = index_entry[8] | 2635 sidedata_offset = index_entry[8] |