Patchwork [3,of,9] flagutil: move REVIDX_KNOWN_FLAGS source of truth in flagutil (API)

login
register
mail settings
Submitter Pierre-Yves David
Date Aug. 8, 2019, 1:47 a.m.
Message ID <c084756962a2c842af5d.1565228839@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/41215/
State Accepted
Headers show

Comments

Pierre-Yves David - Aug. 8, 2019, 1:47 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1565220514 -7200
#      Thu Aug 08 01:28:34 2019 +0200
# Node ID c084756962a2c842af5dc0e23cc67234e4fb1d59
# Parent  6e9396b0817a0e161ff340eab6aeb9c220b1d4df
# EXP-Topic flag-processors
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r c084756962a2
flagutil: move REVIDX_KNOWN_FLAGS source of truth in flagutil (API)

Since REVIDX_KNOWN_FLAGS is "not really a constant" (extension can update it)
and python integer,... it needs to be the responsability of a single module and
always accessed through the module. We update all the user and move the source
of truth in flagutil.

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -53,7 +53,6 @@  from .revlogutils.flagutil import (
     REVIDX_EXTSTORED,
     REVIDX_FLAGS_ORDER,
     REVIDX_ISCENSORED,
-    REVIDX_KNOWN_FLAGS,
     REVIDX_RAWTEXT_CHANGING_FLAGS,
 )
 from .thirdparty import (
@@ -97,7 +96,6 @@  REVIDX_ELLIPSIS
 REVIDX_EXTSTORED
 REVIDX_DEFAULT_FLAGS
 REVIDX_FLAGS_ORDER
-REVIDX_KNOWN_FLAGS
 REVIDX_RAWTEXT_CHANGING_FLAGS
 
 parsers = policy.importmod(r'parsers')
@@ -155,7 +153,7 @@  def addflagprocessor(flag, processor):
     _insertflagprocessor(flag, processor, flagutil.flagprocessors)
 
 def _insertflagprocessor(flag, processor, flagprocessors):
-    if not flag & REVIDX_KNOWN_FLAGS:
+    if not flag & flagutil.REVIDX_KNOWN_FLAGS:
         msg = _("cannot register processor on unknown flag '%#x'.") % (flag)
         raise error.ProgrammingError(msg)
     if flag not in REVIDX_FLAGS_ORDER:
@@ -173,7 +171,7 @@  def gettype(q):
     return int(q & 0xFFFF)
 
 def offset_type(offset, type):
-    if (type & ~REVIDX_KNOWN_FLAGS) != 0:
+    if (type & ~flagutil.REVIDX_KNOWN_FLAGS) != 0:
         raise ValueError('unknown revlog index flags')
     return int(int(offset) << 16 | type)
 
@@ -685,7 +683,7 @@  class revlog(object):
         # fast path: if no "read" flag processor could change the content,
         # size is rawsize. note: ELLIPSIS is known to not change the content.
         flags = self.flags(rev)
-        if flags & (REVIDX_KNOWN_FLAGS ^ REVIDX_ELLIPSIS) == 0:
+        if flags & (flagutil.REVIDX_KNOWN_FLAGS ^ REVIDX_ELLIPSIS) == 0:
             return self.rawsize(rev)
 
         return len(self.revision(rev, raw=False))
@@ -1752,9 +1750,9 @@  class revlog(object):
             raise error.ProgrammingError(_("invalid '%s' operation") %
                                          operation)
         # Check all flags are known.
-        if flags & ~REVIDX_KNOWN_FLAGS:
+        if flags & ~flagutil.REVIDX_KNOWN_FLAGS:
             raise error.RevlogError(_("incompatible revision flag '%#x'") %
-                                    (flags & ~REVIDX_KNOWN_FLAGS))
+                                    (flags & ~flagutil.REVIDX_KNOWN_FLAGS))
         validatehash = True
         # Depending on the operation (read or write), the order might be
         # reversed due to non-commutative transforms.
diff --git a/mercurial/revlogutils/constants.py b/mercurial/revlogutils/constants.py
--- a/mercurial/revlogutils/constants.py
+++ b/mercurial/revlogutils/constants.py
@@ -11,7 +11,6 @@  from __future__ import absolute_import
 
 from .. import (
     repository,
-    util,
 )
 
 # revlog header flags
@@ -48,7 +47,7 @@  REVIDX_FLAGS_ORDER = [
     REVIDX_ELLIPSIS,
     REVIDX_EXTSTORED,
 ]
-REVIDX_KNOWN_FLAGS = util.bitsfrom(REVIDX_FLAGS_ORDER)
+
 # bitmark for flags that could cause rawdata content change
 REVIDX_RAWTEXT_CHANGING_FLAGS = REVIDX_ISCENSORED | REVIDX_EXTSTORED
 
diff --git a/mercurial/revlogutils/flagutil.py b/mercurial/revlogutils/flagutil.py
--- a/mercurial/revlogutils/flagutil.py
+++ b/mercurial/revlogutils/flagutil.py
@@ -14,10 +14,13 @@  from .constants import (
     REVIDX_EXTSTORED,
     REVIDX_FLAGS_ORDER,
     REVIDX_ISCENSORED,
-    REVIDX_KNOWN_FLAGS,
     REVIDX_RAWTEXT_CHANGING_FLAGS,
 )
 
+from .. import (
+    util
+)
+
 # blanked usage of all the name to prevent pyflakes constraints
 # We need these name available in the module for extensions.
 REVIDX_ISCENSORED
@@ -25,9 +28,10 @@  REVIDX_ELLIPSIS
 REVIDX_EXTSTORED
 REVIDX_DEFAULT_FLAGS
 REVIDX_FLAGS_ORDER
-REVIDX_KNOWN_FLAGS
 REVIDX_RAWTEXT_CHANGING_FLAGS
 
+REVIDX_KNOWN_FLAGS = util.bitsfrom(REVIDX_FLAGS_ORDER)
+
 # Store flag processors (cf. 'addflagprocessor()' to register)
 flagprocessors = {
     REVIDX_ISCENSORED: None,
diff --git a/tests/flagprocessorext.py b/tests/flagprocessorext.py
--- a/tests/flagprocessorext.py
+++ b/tests/flagprocessorext.py
@@ -12,6 +12,9 @@  from mercurial import (
     revlog,
     util,
 )
+from mercurial.revlogutils import (
+    flagutil,
+)
 
 # 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
@@ -58,7 +61,7 @@  def makewrappedfile(obj):
     class wrappedfile(obj.__class__):
         def addrevision(self, text, transaction, link, p1, p2,
                         cachedelta=None, node=None,
-                        flags=revlog.REVIDX_DEFAULT_FLAGS):
+                        flags=flagutil.REVIDX_DEFAULT_FLAGS):
             if b'[NOOP]' in text:
                 flags |= REVIDX_NOOP
 
@@ -102,7 +105,7 @@  def extsetup(ui):
 
     # Teach revlog about our test flags
     flags = [REVIDX_NOOP, REVIDX_BASE64, REVIDX_GZIP, REVIDX_FAIL]
-    revlog.REVIDX_KNOWN_FLAGS |= util.bitsfrom(flags)
+    flagutil.REVIDX_KNOWN_FLAGS |= util.bitsfrom(flags)
     revlog.REVIDX_FLAGS_ORDER.extend(flags)
 
     # Teach exchange to use changegroup 3
diff --git a/tests/simplestorerepo.py b/tests/simplestorerepo.py
--- a/tests/simplestorerepo.py
+++ b/tests/simplestorerepo.py
@@ -42,6 +42,9 @@  from mercurial.utils import (
     interfaceutil,
     storageutil,
 )
+from mercurial.revlogutils import (
+    flagutil,
+)
 
 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
@@ -262,9 +265,9 @@  class filestorage(object):
         if flags == 0:
             return text, True
 
-        if flags & ~revlog.REVIDX_KNOWN_FLAGS:
+        if flags & ~flagutil.REVIDX_KNOWN_FLAGS:
             raise simplestoreerror(_("incompatible revision flag '%#x'") %
-                                   (flags & ~revlog.REVIDX_KNOWN_FLAGS))
+                                   (flags & ~flagutil.REVIDX_KNOWN_FLAGS))
 
         validatehash = True
         # Depending on the operation (read or write), the order might be