comparison mercurial/revlog.py @ 51026:8520db304f01

revlog: drop more file description passing between private function They are no longer used as we are covered by the `reading` context
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 26 Sep 2023 02:54:50 +0200
parents 9011c38b4f65
children 498afb627f78
comparison
equal deleted inserted replaced
51025:9011c38b4f65 51026:8520db304f01
1769 returns True if text is different than what is stored. 1769 returns True if text is different than what is stored.
1770 """ 1770 """
1771 p1, p2 = self.parents(node) 1771 p1, p2 = self.parents(node)
1772 return storageutil.hashrevisionsha1(text, p1, p2) != node 1772 return storageutil.hashrevisionsha1(text, p1, p2) != node
1773 1773
1774 def _getsegmentforrevs(self, startrev, endrev, df=None): 1774 def _getsegmentforrevs(self, startrev, endrev):
1775 """Obtain a segment of raw data corresponding to a range of revisions. 1775 """Obtain a segment of raw data corresponding to a range of revisions.
1776 1776
1777 Accepts the start and end revisions and an optional already-open 1777 Accepts the start and end revisions and an optional already-open
1778 file handle to be used for reading. If the file handle is read, its 1778 file handle to be used for reading. If the file handle is read, its
1779 seek position will not be preserved. 1779 seek position will not be preserved.
1801 if self._inline: 1801 if self._inline:
1802 start += (startrev + 1) * self.index.entry_size 1802 start += (startrev + 1) * self.index.entry_size
1803 end += (endrev + 1) * self.index.entry_size 1803 end += (endrev + 1) * self.index.entry_size
1804 length = end - start 1804 length = end - start
1805 1805
1806 return start, self._segmentfile.read_chunk(start, length, df) 1806 return start, self._segmentfile.read_chunk(start, length)
1807 1807
1808 def _chunk(self, rev, df=None): 1808 def _chunk(self, rev):
1809 """Obtain a single decompressed chunk for a revision. 1809 """Obtain a single decompressed chunk for a revision.
1810 1810
1811 Accepts an integer revision and an optional already-open file handle 1811 Accepts an integer revision and an optional already-open file handle
1812 to be used for reading. If used, the seek position of the file will not 1812 to be used for reading. If used, the seek position of the file will not
1813 be preserved. 1813 be preserved.
1814 1814
1815 Returns a str holding uncompressed data for the requested revision. 1815 Returns a str holding uncompressed data for the requested revision.
1816 """ 1816 """
1817 compression_mode = self.index[rev][10] 1817 compression_mode = self.index[rev][10]
1818 data = self._getsegmentforrevs(rev, rev, df=df)[1] 1818 data = self._getsegmentforrevs(rev, rev)[1]
1819 if compression_mode == COMP_MODE_PLAIN: 1819 if compression_mode == COMP_MODE_PLAIN:
1820 return data 1820 return data
1821 elif compression_mode == COMP_MODE_DEFAULT: 1821 elif compression_mode == COMP_MODE_DEFAULT:
1822 return self._decompressor(data) 1822 return self._decompressor(data)
1823 elif compression_mode == COMP_MODE_INLINE: 1823 elif compression_mode == COMP_MODE_INLINE:
1825 else: 1825 else:
1826 msg = b'unknown compression mode %d' 1826 msg = b'unknown compression mode %d'
1827 msg %= compression_mode 1827 msg %= compression_mode
1828 raise error.RevlogError(msg) 1828 raise error.RevlogError(msg)
1829 1829
1830 def _chunks(self, revs, df=None, targetsize=None): 1830 def _chunks(self, revs, targetsize=None):
1831 """Obtain decompressed chunks for the specified revisions. 1831 """Obtain decompressed chunks for the specified revisions.
1832 1832
1833 Accepts an iterable of numeric revisions that are assumed to be in 1833 Accepts an iterable of numeric revisions that are assumed to be in
1834 ascending order. Also accepts an optional already-open file handle 1834 ascending order. Also accepts an optional already-open file handle
1835 to be used for reading. If used, the seek position of the file will 1835 to be used for reading. If used, the seek position of the file will
1864 for lastrev in revschunk[::-1]: 1864 for lastrev in revschunk[::-1]:
1865 if length(lastrev) != 0: 1865 if length(lastrev) != 0:
1866 break 1866 break
1867 1867
1868 try: 1868 try:
1869 offset, data = self._getsegmentforrevs(firstrev, lastrev, df=df) 1869 offset, data = self._getsegmentforrevs(firstrev, lastrev)
1870 except OverflowError: 1870 except OverflowError:
1871 # issue4215 - we can't cache a run of chunks greater than 1871 # issue4215 - we can't cache a run of chunks greater than
1872 # 2G on Windows 1872 # 2G on Windows
1873 return [self._chunk(rev, df=df) for rev in revschunk] 1873 return [self._chunk(rev) for rev in revschunk]
1874 1874
1875 decomp = self.decompress 1875 decomp = self.decompress
1876 # self._decompressor might be None, but will not be used in that case 1876 # self._decompressor might be None, but will not be used in that case
1877 def_decomp = self._decompressor 1877 def_decomp = self._decompressor
1878 for rev in revschunk: 1878 for rev in revschunk:
1972 rev = nodeorrev 1972 rev = nodeorrev
1973 else: 1973 else:
1974 rev = self.rev(nodeorrev) 1974 rev = self.rev(nodeorrev)
1975 return self._sidedata(rev) 1975 return self._sidedata(rev)
1976 1976
1977 def _revisiondata(self, nodeorrev, _df=None, raw=False): 1977 def _revisiondata(self, nodeorrev, raw=False):
1978 # deal with <nodeorrev> argument type 1978 # deal with <nodeorrev> argument type
1979 if isinstance(nodeorrev, int): 1979 if isinstance(nodeorrev, int):
1980 rev = nodeorrev 1980 rev = nodeorrev
1981 node = self.node(rev) 1981 node = self.node(rev)
1982 else: 1982 else:
1987 if node == self.nullid: 1987 if node == self.nullid:
1988 return b"" 1988 return b""
1989 1989
1990 # ``rawtext`` is the text as stored inside the revlog. Might be the 1990 # ``rawtext`` is the text as stored inside the revlog. Might be the
1991 # revision or might need to be processed to retrieve the revision. 1991 # revision or might need to be processed to retrieve the revision.
1992 rev, rawtext, validated = self._rawtext(node, rev, _df=_df) 1992 rev, rawtext, validated = self._rawtext(node, rev)
1993 1993
1994 if raw and validated: 1994 if raw and validated:
1995 # if we don't want to process the raw text and that raw 1995 # if we don't want to process the raw text and that raw
1996 # text is cached, we can exit early. 1996 # text is cached, we can exit early.
1997 return rawtext 1997 return rawtext
2016 if not validated: 2016 if not validated:
2017 self._revisioncache = (node, rev, rawtext) 2017 self._revisioncache = (node, rev, rawtext)
2018 2018
2019 return text 2019 return text
2020 2020
2021 def _rawtext(self, node, rev, _df=None): 2021 def _rawtext(self, node, rev):
2022 """return the possibly unvalidated rawtext for a revision 2022 """return the possibly unvalidated rawtext for a revision
2023 2023
2024 returns (rev, rawtext, validated) 2024 returns (rev, rawtext, validated)
2025 """ 2025 """
2026 2026
2050 targetsize = None 2050 targetsize = None
2051 rawsize = self.index[rev][2] 2051 rawsize = self.index[rev][2]
2052 if 0 <= rawsize: 2052 if 0 <= rawsize:
2053 targetsize = 4 * rawsize 2053 targetsize = 4 * rawsize
2054 2054
2055 bins = self._chunks(chain, df=_df, targetsize=targetsize) 2055 bins = self._chunks(chain, targetsize=targetsize)
2056 if basetext is None: 2056 if basetext is None:
2057 basetext = bytes(bins[0]) 2057 basetext = bytes(bins[0])
2058 bins = bins[1:] 2058 bins = bins[1:]
2059 2059
2060 rawtext = mdiff.patches(basetext, bins) 2060 rawtext = mdiff.patches(basetext, bins)