Mercurial > public > mercurial-scm > hg
annotate mercurial/revlogutils/__init__.py @ 47395:a669404f0f4a
revlog: add a function to build index entry tuple
Keeping index entry as tuple make sense for performance reason, however it does
not means we need to manually build that tuple for all piece of python code that
are not performance critical.
So we add a nice function responsible to build the tuple using argument using
explicit keyword argument.
Differential Revision: https://phab.mercurial-scm.org/D10793
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Sun, 30 May 2021 17:10:56 +0200 |
parents | ac60a1366a49 |
children | 34cc102c73f5 |
rev | line source |
---|---|
43524
a7c0c5b5a50f
revlog: introduce an explicit NodeMap class for pure code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39329
diff
changeset
|
1 # mercurial.revlogutils -- basic utilities for revlog |
a7c0c5b5a50f
revlog: introduce an explicit NodeMap class for pure code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39329
diff
changeset
|
2 # |
a7c0c5b5a50f
revlog: introduce an explicit NodeMap class for pure code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39329
diff
changeset
|
3 # Copyright 2019 Pierre-Yves David <pierre-yves.david@octobus.net> |
a7c0c5b5a50f
revlog: introduce an explicit NodeMap class for pure code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39329
diff
changeset
|
4 # |
a7c0c5b5a50f
revlog: introduce an explicit NodeMap class for pure code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39329
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
a7c0c5b5a50f
revlog: introduce an explicit NodeMap class for pure code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39329
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
a7c0c5b5a50f
revlog: introduce an explicit NodeMap class for pure code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39329
diff
changeset
|
7 |
a7c0c5b5a50f
revlog: introduce an explicit NodeMap class for pure code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
39329
diff
changeset
|
8 from __future__ import absolute_import |
47394
ac60a1366a49
revlog: move `offset_type` to `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44034
diff
changeset
|
9 |
ac60a1366a49
revlog: move `offset_type` to `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44034
diff
changeset
|
10 from ..interfaces import repository |
ac60a1366a49
revlog: move `offset_type` to `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44034
diff
changeset
|
11 |
47395
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
12 # See mercurial.revlogutils.constants for doc |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
13 COMP_MODE_INLINE = 2 |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
14 |
47394
ac60a1366a49
revlog: move `offset_type` to `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44034
diff
changeset
|
15 |
ac60a1366a49
revlog: move `offset_type` to `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44034
diff
changeset
|
16 def offset_type(offset, type): |
ac60a1366a49
revlog: move `offset_type` to `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44034
diff
changeset
|
17 if (type & ~repository.REVISION_FLAGS_KNOWN) != 0: |
ac60a1366a49
revlog: move `offset_type` to `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44034
diff
changeset
|
18 raise ValueError(b'unknown revlog index flags: %d' % type) |
ac60a1366a49
revlog: move `offset_type` to `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44034
diff
changeset
|
19 return int(int(offset) << 16 | type) |
47395
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
20 |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
21 |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
22 def entry( |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
23 data_offset, |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
24 data_compressed_length, |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
25 data_delta_base, |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
26 link_rev, |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
27 parent_rev_1, |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
28 parent_rev_2, |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
29 node_id, |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
30 flags=0, |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
31 data_uncompressed_length=-1, |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
32 data_compression_mode=COMP_MODE_INLINE, |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
33 sidedata_offset=0, |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
34 sidedata_compressed_length=0, |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
35 sidedata_compression_mode=COMP_MODE_INLINE, |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
36 ): |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
37 """Build one entry from symbolic name |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
38 |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
39 This is useful to abstract the actual detail of how we build the entry |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
40 tuple for caller who don't care about it. |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
41 |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
42 This should always be called using keyword arguments. Some arguments have |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
43 default value, this match the value used by index version that does not store such data. |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
44 """ |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
45 return ( |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
46 offset_type(data_offset, flags), |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
47 data_compressed_length, |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
48 data_uncompressed_length, |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
49 data_delta_base, |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
50 link_rev, |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
51 parent_rev_1, |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
52 parent_rev_2, |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
53 node_id, |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
54 sidedata_offset, |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
55 sidedata_compressed_length, |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
56 data_compression_mode, |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
57 sidedata_compression_mode, |
a669404f0f4a
revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47394
diff
changeset
|
58 ) |