revlog: move `offset_type` to `revlogutils`
This multiple module are using this so it make sense to move it at the utility
level.
Differential Revision: https://phab.mercurial-scm.org/D10792
--- a/mercurial/bundlerepo.py Sat May 22 00:06:22 2021 +0200
+++ b/mercurial/bundlerepo.py Sun May 30 16:19:36 2021 +0200
@@ -39,6 +39,7 @@
phases,
pycompat,
revlog,
+ revlogutils,
util,
vfs as vfsmod,
)
@@ -95,7 +96,7 @@
baserev = self.rev(deltabase)
# start, size, full unc. size, base (unused), link, p1, p2, node, sidedata_offset (unused), sidedata_size (unused)
e = (
- revlog.offset_type(start, flags),
+ revlogutils.offset_type(start, flags),
size,
-1,
baserev,
--- a/mercurial/pure/parsers.py Sat May 22 00:06:22 2021 +0200
+++ b/mercurial/pure/parsers.py Sun May 30 16:19:36 2021 +0200
@@ -17,6 +17,7 @@
from .. import (
error,
pycompat,
+ revlogutils,
util,
)
@@ -42,10 +43,6 @@
return int(q & 0xFFFF)
-def offset_type(offset, type):
- return int(int(offset) << 16 | type)
-
-
class BaseIndexObject(object):
# Can I be passed to an algorithme implemented in Rust ?
rust_ext_compat = 0
@@ -145,7 +142,8 @@
data = self._data[index : index + self.entry_size]
r = self._unpack_entry(i, data)
if self._lgt and i == 0:
- r = (offset_type(0, gettype(r[0])),) + r[1:]
+ offset = revlogutils.offset_type(0, gettype(r[0]))
+ r = (offset,) + r[1:]
return r
def _unpack_entry(self, rev, data):
--- a/mercurial/revlog.py Sat May 22 00:06:22 2021 +0200
+++ b/mercurial/revlog.py Sun May 30 16:19:36 2021 +0200
@@ -72,6 +72,7 @@
mdiff,
policy,
pycompat,
+ revlogutils,
templatefilters,
util,
)
@@ -146,12 +147,6 @@
)
-def offset_type(offset, type):
- if (type & ~flagutil.REVIDX_KNOWN_FLAGS) != 0:
- raise ValueError(b'unknown revlog index flags')
- return int(int(offset) << 16 | type)
-
-
def _verify_revision(rl, skipflags, state, node):
"""Verify the integrity of the given revlog ``node`` while providing a hook
point for extensions to influence the operation."""
@@ -2590,7 +2585,7 @@
sidedata_offset = 0
e = (
- offset_type(offset, flags),
+ revlogutils.offset_type(offset, flags),
deltainfo.deltalen,
textlen,
deltainfo.base,
--- a/mercurial/revlogutils/__init__.py Sat May 22 00:06:22 2021 +0200
+++ b/mercurial/revlogutils/__init__.py Sun May 30 16:19:36 2021 +0200
@@ -6,3 +6,11 @@
# GNU General Public License version 2 or any later version.
from __future__ import absolute_import
+
+from ..interfaces import repository
+
+
+def offset_type(offset, type):
+ if (type & ~repository.REVISION_FLAGS_KNOWN) != 0:
+ raise ValueError(b'unknown revlog index flags: %d' % type)
+ return int(int(offset) << 16 | type)
--- a/mercurial/revlogutils/revlogv0.py Sat May 22 00:06:22 2021 +0200
+++ b/mercurial/revlogutils/revlogv0.py Sun May 30 16:19:36 2021 +0200
@@ -18,6 +18,7 @@
error,
node,
pycompat,
+ revlogutils,
util,
)
@@ -35,12 +36,6 @@
return int(q & 0xFFFF)
-def offset_type(offset, type):
- if (type & ~flagutil.REVIDX_KNOWN_FLAGS) != 0:
- raise ValueError(b'unknown revlog index flags')
- return int(int(offset) << 16 | type)
-
-
class revlogoldindex(list):
rust_ext_compat = 0
entry_size = INDEX_ENTRY_V0.size
@@ -143,7 +138,7 @@
e = INDEX_ENTRY_V0.unpack(cur)
# transform to revlogv1 format
e2 = (
- offset_type(e[0], 0),
+ revlogutils.offset_type(e[0], 0),
e[1],
-1,
e[2],
--- a/tests/flagprocessorext.py Sat May 22 00:06:22 2021 +0200
+++ b/tests/flagprocessorext.py Sun May 30 16:19:36 2021 +0200
@@ -13,6 +13,7 @@
util,
)
from mercurial.revlogutils import flagutil
+from mercurial.interfaces import repository
# Test only: These flags are defined here only in the context of testing the
# behavior of the flag processor. The canonical way to add flags is to get in
@@ -131,6 +132,7 @@
# Teach revlog about our test flags
flags = [REVIDX_NOOP, REVIDX_BASE64, REVIDX_GZIP, REVIDX_FAIL]
flagutil.REVIDX_KNOWN_FLAGS |= util.bitsfrom(flags)
+ repository.REVISION_FLAGS_KNOWN |= util.bitsfrom(flags)
revlog.REVIDX_FLAGS_ORDER.extend(flags)
# Teach exchange to use changegroup 3