Mercurial > hg-stable
comparison contrib/perf.py @ 47089:4c041c71ec01
revlog: introduce an explicit tracking of what the revlog is about
Since the dawn of time, people have been forced to rely to lossy introspection
of the index filename to determine what the purpose and role of the revlog they
encounter is. This is hacky, error prone, inflexible, abstraction-leaky,
<insert-your-own-complaints-here>.
In f63299ee7e4d Raphaël introduced a new attribute to track this information:
`revlog_kind`. However it is initialized in an odd place and various instances
end up not having it set. In addition is only tracking some of the information
we end up having to introspect in various pieces of code.
So we add a new attribute that holds more data and is more strictly enforced.
This work is done in collaboration with Raphaël.
The `revlog_kind` one will be removed/adapted in the next changeset. We expect
to be able to clean up various existing piece of code and to simplify coming
work around the newer revlog format.
Differential Revision: https://phab.mercurial-scm.org/D10352
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 06 Apr 2021 05:20:24 +0200 |
parents | 5e64c93d5f94 |
children | a07d5cb03a85 |
comparison
equal
deleted
inserted
replaced
47088:3e381eb557f3 | 47089:4c041c71ec01 |
---|---|
64 import struct | 64 import struct |
65 import sys | 65 import sys |
66 import tempfile | 66 import tempfile |
67 import threading | 67 import threading |
68 import time | 68 import time |
69 | |
70 import mercurial.revlog | |
69 from mercurial import ( | 71 from mercurial import ( |
70 changegroup, | 72 changegroup, |
71 cmdutil, | 73 cmdutil, |
72 commands, | 74 commands, |
73 copies, | 75 copies, |
74 error, | 76 error, |
75 extensions, | 77 extensions, |
76 hg, | 78 hg, |
77 mdiff, | 79 mdiff, |
78 merge, | 80 merge, |
79 revlog, | |
80 util, | 81 util, |
81 ) | 82 ) |
82 | 83 |
83 # for "historical portability": | 84 # for "historical portability": |
84 # try to import modules separately (in dict order), and ignore | 85 # try to import modules separately (in dict order), and ignore |
116 | 117 |
117 try: | 118 try: |
118 from mercurial import profiling | 119 from mercurial import profiling |
119 except ImportError: | 120 except ImportError: |
120 profiling = None | 121 profiling = None |
122 | |
123 try: | |
124 from mercurial.revlogutils import constants as revlog_constants | |
125 | |
126 perf_rl_kind = (revlog_constants.KIND_OTHER, b'created-by-perf') | |
127 | |
128 def revlog(opener, *args, **kwargs): | |
129 return mercurial.revlog.revlog(opener, perf_rl_kind, *args, **kwargs) | |
130 | |
131 | |
132 except (ImportError, AttributeError): | |
133 perf_rl_kind = None | |
134 | |
135 def revlog(opener, *args, **kwargs): | |
136 return mercurial.revlog.revlog(opener, *args, **kwargs) | |
121 | 137 |
122 | 138 |
123 def identity(a): | 139 def identity(a): |
124 return a | 140 return a |
125 | 141 |
1807 timer, fm = gettimer(ui, opts) | 1823 timer, fm = gettimer(ui, opts) |
1808 import mercurial.revlog | 1824 import mercurial.revlog |
1809 | 1825 |
1810 mercurial.revlog._prereadsize = 2 ** 24 # disable lazy parser in old hg | 1826 mercurial.revlog._prereadsize = 2 ** 24 # disable lazy parser in old hg |
1811 n = scmutil.revsingle(repo, rev).node() | 1827 n = scmutil.revsingle(repo, rev).node() |
1812 cl = mercurial.revlog.revlog(getsvfs(repo), b"00changelog.i") | 1828 |
1829 cl = revlog(getsvfs(repo), indexfile=b"00changelog.i") | |
1813 | 1830 |
1814 def d(): | 1831 def d(): |
1815 cl.rev(n) | 1832 cl.rev(n) |
1816 clearcaches(cl) | 1833 clearcaches(cl) |
1817 | 1834 |
2600 if version == 1: | 2617 if version == 1: |
2601 inline = header & (1 << 16) | 2618 inline = header & (1 << 16) |
2602 else: | 2619 else: |
2603 raise error.Abort(b'unsupported revlog version: %d' % version) | 2620 raise error.Abort(b'unsupported revlog version: %d' % version) |
2604 | 2621 |
2605 parse_index_v1 = getattr(revlog, 'parse_index_v1', None) | 2622 parse_index_v1 = getattr(mercurial.revlog, 'parse_index_v1', None) |
2606 if parse_index_v1 is None: | 2623 if parse_index_v1 is None: |
2607 parse_index_v1 = revlog.revlogio().parseindex | 2624 parse_index_v1 = mercurial.revlog.revlogio().parseindex |
2608 | 2625 |
2609 rllen = len(rl) | 2626 rllen = len(rl) |
2610 | 2627 |
2611 node0 = rl.node(0) | 2628 node0 = rl.node(0) |
2612 node25 = rl.node(rllen // 4) | 2629 node25 = rl.node(rllen // 4) |
2618 allrevsrev = list(reversed(allrevs)) | 2635 allrevsrev = list(reversed(allrevs)) |
2619 allnodes = [rl.node(rev) for rev in range(rllen)] | 2636 allnodes = [rl.node(rev) for rev in range(rllen)] |
2620 allnodesrev = list(reversed(allnodes)) | 2637 allnodesrev = list(reversed(allnodes)) |
2621 | 2638 |
2622 def constructor(): | 2639 def constructor(): |
2623 revlog.revlog(opener, indexfile) | 2640 revlog(opener, indexfile=indexfile) |
2624 | 2641 |
2625 def read(): | 2642 def read(): |
2626 with opener(indexfile) as fh: | 2643 with opener(indexfile) as fh: |
2627 fh.read() | 2644 fh.read() |
2628 | 2645 |
3040 # instantiate a new revlog from the temporary copy | 3057 # instantiate a new revlog from the temporary copy |
3041 ui.debug('truncating adding to be rewritten\n') | 3058 ui.debug('truncating adding to be rewritten\n') |
3042 vfs = vfsmod.vfs(tmpdir) | 3059 vfs = vfsmod.vfs(tmpdir) |
3043 vfs.options = getattr(orig.opener, 'options', None) | 3060 vfs.options = getattr(orig.opener, 'options', None) |
3044 | 3061 |
3045 dest = revlog.revlog( | 3062 dest = revlog( |
3046 vfs, indexfile=indexname, datafile=dataname, **revlogkwargs | 3063 vfs, indexfile=indexname, datafile=dataname, **revlogkwargs |
3047 ) | 3064 ) |
3048 if dest._inline: | 3065 if dest._inline: |
3049 raise error.Abort('not supporting inline revlog (yet)') | 3066 raise error.Abort('not supporting inline revlog (yet)') |
3050 # make sure internals are initialized | 3067 # make sure internals are initialized |