[Commented On] D10792: revlog: move `offset_type` to `revlogutils`

baymax (Baymax, Your Personal Patch-care Companion) phabricator at mercurial-scm.org
Wed Jun 2 11:44:45 UTC 2021


baymax added a comment.
baymax updated this revision to Diff 28417.


  ✅ refresh by Heptapod after a successful CI run (🐙 💚)

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D10792?vs=28402&id=28417

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D10792/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D10792

AFFECTED FILES
  mercurial/bundlerepo.py
  mercurial/pure/parsers.py
  mercurial/revlog.py
  mercurial/revlogutils/__init__.py
  mercurial/revlogutils/revlogv0.py
  tests/flagprocessorext.py

CHANGE DETAILS

diff --git a/tests/flagprocessorext.py b/tests/flagprocessorext.py
--- a/tests/flagprocessorext.py
+++ b/tests/flagprocessorext.py
@@ -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
diff --git a/mercurial/revlogutils/revlogv0.py b/mercurial/revlogutils/revlogv0.py
--- a/mercurial/revlogutils/revlogv0.py
+++ b/mercurial/revlogutils/revlogv0.py
@@ -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],
diff --git a/mercurial/revlogutils/__init__.py b/mercurial/revlogutils/__init__.py
--- a/mercurial/revlogutils/__init__.py
+++ b/mercurial/revlogutils/__init__.py
@@ -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)
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -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,
diff --git a/mercurial/pure/parsers.py b/mercurial/pure/parsers.py
--- a/mercurial/pure/parsers.py
+++ b/mercurial/pure/parsers.py
@@ -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):
diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py
--- a/mercurial/bundlerepo.py
+++ b/mercurial/bundlerepo.py
@@ -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,



To: marmoute, indygreg, #hg-reviewers, Alphare
Cc: Alphare, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20210602/29e98e16/attachment-0002.html>


More information about the Mercurial-patches mailing list