Mercurial > hg
comparison mercurial/revlog.py @ 47036:5e64c93d5f94
revlog: remove the revlogio class
The class only contains a single `parseindex` method. Lets just make it a
function and remove the `revlogio` class. It served us well but became thinner
and thinner overtime.
Differential Revision: https://phab.mercurial-scm.org/D10509
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Sat, 01 May 2021 14:47:39 +0200 |
parents | 0d8ff1f4ab0c |
children | d57386e5c80e |
comparison
equal
deleted
inserted
replaced
47035:4f2b5f9d8cc4 | 47036:5e64c93d5f94 |
---|---|
35 from .pycompat import getattr | 35 from .pycompat import getattr |
36 from .revlogutils.constants import ( | 36 from .revlogutils.constants import ( |
37 FLAG_GENERALDELTA, | 37 FLAG_GENERALDELTA, |
38 FLAG_INLINE_DATA, | 38 FLAG_INLINE_DATA, |
39 INDEX_ENTRY_V0, | 39 INDEX_ENTRY_V0, |
40 INDEX_ENTRY_V1, | |
41 INDEX_ENTRY_V2, | |
42 INDEX_HEADER, | 40 INDEX_HEADER, |
43 REVLOGV0, | 41 REVLOGV0, |
44 REVLOGV1, | 42 REVLOGV1, |
45 REVLOGV1_FLAGS, | 43 REVLOGV1_FLAGS, |
46 REVLOGV2, | 44 REVLOGV2, |
285 entry[7], | 283 entry[7], |
286 ) | 284 ) |
287 return INDEX_ENTRY_V0.pack(*e2) | 285 return INDEX_ENTRY_V0.pack(*e2) |
288 | 286 |
289 | 287 |
290 class revlogoldio(object): | 288 def parse_index_v0(data, inline): |
291 def parseindex(self, data, inline): | 289 s = INDEX_ENTRY_V0.size |
292 s = INDEX_ENTRY_V0.size | 290 index = [] |
293 index = [] | 291 nodemap = nodemaputil.NodeMap({sha1nodeconstants.nullid: nullrev}) |
294 nodemap = nodemaputil.NodeMap({sha1nodeconstants.nullid: nullrev}) | 292 n = off = 0 |
295 n = off = 0 | 293 l = len(data) |
296 l = len(data) | 294 while off + s <= l: |
297 while off + s <= l: | 295 cur = data[off : off + s] |
298 cur = data[off : off + s] | 296 off += s |
299 off += s | 297 e = INDEX_ENTRY_V0.unpack(cur) |
300 e = INDEX_ENTRY_V0.unpack(cur) | 298 # transform to revlogv1 format |
301 # transform to revlogv1 format | 299 e2 = ( |
302 e2 = ( | 300 offset_type(e[0], 0), |
303 offset_type(e[0], 0), | 301 e[1], |
304 e[1], | 302 -1, |
305 -1, | 303 e[2], |
306 e[2], | 304 e[3], |
307 e[3], | 305 nodemap.get(e[4], nullrev), |
308 nodemap.get(e[4], nullrev), | 306 nodemap.get(e[5], nullrev), |
309 nodemap.get(e[5], nullrev), | 307 e[6], |
310 e[6], | 308 ) |
311 ) | 309 index.append(e2) |
312 index.append(e2) | 310 nodemap[e[6]] = n |
313 nodemap[e[6]] = n | 311 n += 1 |
314 n += 1 | 312 |
315 | 313 index = revlogoldindex(index) |
316 index = revlogoldindex(index) | 314 return index, None |
317 return index, None | 315 |
316 | |
317 def parse_index_v1(data, inline): | |
318 # call the C implementation to parse the index data | |
319 index, cache = parsers.parse_index2(data, inline) | |
320 return index, cache | |
321 | |
322 | |
323 def parse_index_v2(data, inline): | |
324 # call the C implementation to parse the index data | |
325 index, cache = parsers.parse_index2(data, inline, revlogv2=True) | |
326 return index, cache | |
327 | |
328 | |
329 if util.safehasattr(parsers, 'parse_index_devel_nodemap'): | |
330 | |
331 def parse_index_v1_nodemap(data, inline): | |
332 index, cache = parsers.parse_index_devel_nodemap(data, inline) | |
333 return index, cache | |
334 | |
335 | |
336 else: | |
337 parse_index_v1_nodemap = None | |
338 | |
339 | |
340 def parse_index_v1_mixed(data, inline): | |
341 index, cache = parse_index_v1(data, inline) | |
342 return rustrevlog.MixedIndex(index), cache | |
318 | 343 |
319 | 344 |
320 # corresponds to uncompressed length of indexformatng (2 gigs, 4-byte | 345 # corresponds to uncompressed length of indexformatng (2 gigs, 4-byte |
321 # signed integer) | 346 # signed integer) |
322 _maxentrysize = 0x7FFFFFFF | 347 _maxentrysize = 0x7FFFFFFF |
323 | |
324 | |
325 class revlogio(object): | |
326 def parseindex(self, data, inline): | |
327 # call the C implementation to parse the index data | |
328 index, cache = parsers.parse_index2(data, inline) | |
329 return index, cache | |
330 | |
331 | |
332 class revlogv2io(object): | |
333 def parseindex(self, data, inline): | |
334 index, cache = parsers.parse_index2(data, inline, revlogv2=True) | |
335 return index, cache | |
336 | |
337 | |
338 NodemapRevlogIO = None | |
339 | |
340 if util.safehasattr(parsers, 'parse_index_devel_nodemap'): | |
341 | |
342 class NodemapRevlogIO(revlogio): | |
343 """A debug oriented IO class that return a PersistentNodeMapIndexObject | |
344 | |
345 The PersistentNodeMapIndexObject object is meant to test the persistent nodemap feature. | |
346 """ | |
347 | |
348 def parseindex(self, data, inline): | |
349 index, cache = parsers.parse_index_devel_nodemap(data, inline) | |
350 return index, cache | |
351 | |
352 | |
353 class rustrevlogio(revlogio): | |
354 def parseindex(self, data, inline): | |
355 index, cache = super(rustrevlogio, self).parseindex(data, inline) | |
356 return rustrevlog.MixedIndex(index), cache | |
357 | 348 |
358 | 349 |
359 class revlog(object): | 350 class revlog(object): |
360 """ | 351 """ |
361 the underlying revision storage object | 352 the underlying revision storage object |
612 self._storedeltachains = True | 603 self._storedeltachains = True |
613 | 604 |
614 devel_nodemap = ( | 605 devel_nodemap = ( |
615 self.nodemap_file | 606 self.nodemap_file |
616 and opts.get(b'devel-force-nodemap', False) | 607 and opts.get(b'devel-force-nodemap', False) |
617 and NodemapRevlogIO is not None | 608 and parse_index_v1_nodemap is not None |
618 ) | 609 ) |
619 | 610 |
620 use_rust_index = False | 611 use_rust_index = False |
621 if rustrevlog is not None: | 612 if rustrevlog is not None: |
622 if self.nodemap_file is not None: | 613 if self.nodemap_file is not None: |
623 use_rust_index = True | 614 use_rust_index = True |
624 else: | 615 else: |
625 use_rust_index = self.opener.options.get(b'rust.index') | 616 use_rust_index = self.opener.options.get(b'rust.index') |
626 | 617 |
627 self._io = revlogio() | 618 self._parse_index = parse_index_v1 |
628 if self.version == REVLOGV0: | 619 if self.version == REVLOGV0: |
629 self._io = revlogoldio() | 620 self._parse_index = parse_index_v0 |
630 elif fmt == REVLOGV2: | 621 elif fmt == REVLOGV2: |
631 self._io = revlogv2io() | 622 self._parse_index = parse_index_v2 |
632 elif devel_nodemap: | 623 elif devel_nodemap: |
633 self._io = NodemapRevlogIO() | 624 self._parse_index = parse_index_v1_nodemap |
634 elif use_rust_index: | 625 elif use_rust_index: |
635 self._io = rustrevlogio() | 626 self._parse_index = parse_index_v1_mixed |
636 try: | 627 try: |
637 d = self._io.parseindex(indexdata, self._inline) | 628 d = self._parse_index(indexdata, self._inline) |
638 index, _chunkcache = d | 629 index, _chunkcache = d |
639 use_nodemap = ( | 630 use_nodemap = ( |
640 not self._inline | 631 not self._inline |
641 and self.nodemap_file is not None | 632 and self.nodemap_file is not None |
642 and util.safehasattr(index, 'update_nodemap_data') | 633 and util.safehasattr(index, 'update_nodemap_data') |
2047 trindex = r | 2038 trindex = r |
2048 | 2039 |
2049 with self._indexfp(b'w') as fp: | 2040 with self._indexfp(b'w') as fp: |
2050 self.version &= ~FLAG_INLINE_DATA | 2041 self.version &= ~FLAG_INLINE_DATA |
2051 self._inline = False | 2042 self._inline = False |
2052 io = self._io | |
2053 for i in self: | 2043 for i in self: |
2054 e = self.index.entry_binary(i, self.version) | 2044 e = self.index.entry_binary(i, self.version) |
2055 fp.write(e) | 2045 fp.write(e) |
2056 | 2046 |
2057 # the temp file replace the real index when we exit the context | 2047 # the temp file replace the real index when we exit the context |
2982 | 2972 |
2983 # This is a bit dangerous. We could easily have a mismatch of state. | 2973 # This is a bit dangerous. We could easily have a mismatch of state. |
2984 newrl = revlog(self.opener, newindexfile, newdatafile, censorable=True) | 2974 newrl = revlog(self.opener, newindexfile, newdatafile, censorable=True) |
2985 newrl.version = self.version | 2975 newrl.version = self.version |
2986 newrl._generaldelta = self._generaldelta | 2976 newrl._generaldelta = self._generaldelta |
2987 newrl._io = self._io | 2977 newrl._parse_index = self._parse_index |
2988 | 2978 |
2989 for rev in self.revs(): | 2979 for rev in self.revs(): |
2990 node = self.node(rev) | 2980 node = self.node(rev) |
2991 p1, p2 = self.parents(node) | 2981 p1, p2 = self.parents(node) |
2992 | 2982 |