# HG changeset patch # User Pierre-Yves David # Date 1565220514 -7200 # 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 -r 05c80f9ef100 -r 92ac6b1697a7 mercurial/revlog.py --- a/mercurial/revlog.py Thu Aug 08 01:04:48 2019 +0200 +++ b/mercurial/revlog.py Thu Aug 08 01:28:34 2019 +0200 @@ -53,7 +53,6 @@ REVIDX_EXTSTORED, REVIDX_FLAGS_ORDER, REVIDX_ISCENSORED, - REVIDX_KNOWN_FLAGS, REVIDX_RAWTEXT_CHANGING_FLAGS, ) from .thirdparty import ( @@ -97,7 +96,6 @@ REVIDX_EXTSTORED REVIDX_DEFAULT_FLAGS REVIDX_FLAGS_ORDER -REVIDX_KNOWN_FLAGS REVIDX_RAWTEXT_CHANGING_FLAGS parsers = policy.importmod(r'parsers') @@ -155,7 +153,7 @@ _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 @@ 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 @@ # 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 @@ 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 -r 05c80f9ef100 -r 92ac6b1697a7 mercurial/revlogutils/constants.py --- a/mercurial/revlogutils/constants.py Thu Aug 08 01:04:48 2019 +0200 +++ b/mercurial/revlogutils/constants.py Thu Aug 08 01:28:34 2019 +0200 @@ -11,7 +11,6 @@ from .. import ( repository, - util, ) # revlog header flags @@ -48,7 +47,7 @@ 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 -r 05c80f9ef100 -r 92ac6b1697a7 mercurial/revlogutils/flagutil.py --- a/mercurial/revlogutils/flagutil.py Thu Aug 08 01:04:48 2019 +0200 +++ b/mercurial/revlogutils/flagutil.py Thu Aug 08 01:28:34 2019 +0200 @@ -14,10 +14,13 @@ 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_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 -r 05c80f9ef100 -r 92ac6b1697a7 tests/flagprocessorext.py --- a/tests/flagprocessorext.py Thu Aug 08 01:04:48 2019 +0200 +++ b/tests/flagprocessorext.py Thu Aug 08 01:28:34 2019 +0200 @@ -12,6 +12,9 @@ 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 @@ 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 @@ # 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 -r 05c80f9ef100 -r 92ac6b1697a7 tests/simplestorerepo.py --- a/tests/simplestorerepo.py Thu Aug 08 01:04:48 2019 +0200 +++ b/tests/simplestorerepo.py Thu Aug 08 01:28:34 2019 +0200 @@ -42,6 +42,9 @@ 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 @@ 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