# HG changeset patch # User Pierre-Yves David # Date 2019-08-07 23:28:34 # Node ID 92ac6b1697a7aabd408d97bd0ccf1164db500f29 # Parent 05c80f9ef100ddd81d6b7b6e65f47afb3092d489 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. 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)) @@ -1762,9 +1760,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