Mercurial > hg
comparison contrib/perf.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 | 3c9208702db3 |
children | 4c041c71ec01 |
comparison
equal
deleted
inserted
replaced
47035:4f2b5f9d8cc4 | 47036:5e64c93d5f94 |
---|---|
2596 data = opener.read(indexfile) | 2596 data = opener.read(indexfile) |
2597 | 2597 |
2598 header = struct.unpack(b'>I', data[0:4])[0] | 2598 header = struct.unpack(b'>I', data[0:4])[0] |
2599 version = header & 0xFFFF | 2599 version = header & 0xFFFF |
2600 if version == 1: | 2600 if version == 1: |
2601 revlogio = revlog.revlogio() | |
2602 inline = header & (1 << 16) | 2601 inline = header & (1 << 16) |
2603 else: | 2602 else: |
2604 raise error.Abort(b'unsupported revlog version: %d' % version) | 2603 raise error.Abort(b'unsupported revlog version: %d' % version) |
2604 | |
2605 parse_index_v1 = getattr(revlog, 'parse_index_v1', None) | |
2606 if parse_index_v1 is None: | |
2607 parse_index_v1 = revlog.revlogio().parseindex | |
2605 | 2608 |
2606 rllen = len(rl) | 2609 rllen = len(rl) |
2607 | 2610 |
2608 node0 = rl.node(0) | 2611 node0 = rl.node(0) |
2609 node25 = rl.node(rllen // 4) | 2612 node25 = rl.node(rllen // 4) |
2622 def read(): | 2625 def read(): |
2623 with opener(indexfile) as fh: | 2626 with opener(indexfile) as fh: |
2624 fh.read() | 2627 fh.read() |
2625 | 2628 |
2626 def parseindex(): | 2629 def parseindex(): |
2627 revlogio.parseindex(data, inline) | 2630 parse_index_v1(data, inline) |
2628 | 2631 |
2629 def getentry(revornode): | 2632 def getentry(revornode): |
2630 index = revlogio.parseindex(data, inline)[0] | 2633 index = parse_index_v1(data, inline)[0] |
2631 index[revornode] | 2634 index[revornode] |
2632 | 2635 |
2633 def getentries(revs, count=1): | 2636 def getentries(revs, count=1): |
2634 index = revlogio.parseindex(data, inline)[0] | 2637 index = parse_index_v1(data, inline)[0] |
2635 | 2638 |
2636 for i in range(count): | 2639 for i in range(count): |
2637 for rev in revs: | 2640 for rev in revs: |
2638 index[rev] | 2641 index[rev] |
2639 | 2642 |
2640 def resolvenode(node): | 2643 def resolvenode(node): |
2641 index = revlogio.parseindex(data, inline)[0] | 2644 index = parse_index_v1(data, inline)[0] |
2642 rev = getattr(index, 'rev', None) | 2645 rev = getattr(index, 'rev', None) |
2643 if rev is None: | 2646 if rev is None: |
2644 nodemap = getattr( | 2647 nodemap = getattr(parse_index_v1(data, inline)[0], 'nodemap', None) |
2645 revlogio.parseindex(data, inline)[0], 'nodemap', None | |
2646 ) | |
2647 # This only works for the C code. | 2648 # This only works for the C code. |
2648 if nodemap is None: | 2649 if nodemap is None: |
2649 return | 2650 return |
2650 rev = nodemap.__getitem__ | 2651 rev = nodemap.__getitem__ |
2651 | 2652 |
2653 rev(node) | 2654 rev(node) |
2654 except error.RevlogError: | 2655 except error.RevlogError: |
2655 pass | 2656 pass |
2656 | 2657 |
2657 def resolvenodes(nodes, count=1): | 2658 def resolvenodes(nodes, count=1): |
2658 index = revlogio.parseindex(data, inline)[0] | 2659 index = parse_index_v1(data, inline)[0] |
2659 rev = getattr(index, 'rev', None) | 2660 rev = getattr(index, 'rev', None) |
2660 if rev is None: | 2661 if rev is None: |
2661 nodemap = getattr( | 2662 nodemap = getattr(parse_index_v1(data, inline)[0], 'nodemap', None) |
2662 revlogio.parseindex(data, inline)[0], 'nodemap', None | |
2663 ) | |
2664 # This only works for the C code. | 2663 # This only works for the C code. |
2665 if nodemap is None: | 2664 if nodemap is None: |
2666 return | 2665 return |
2667 rev = nodemap.__getitem__ | 2666 rev = nodemap.__getitem__ |
2668 | 2667 |