mercurial/revlogutils/flagutil.py
changeset 42731 5109217a9ab6
parent 42730 92ac6b1697a7
child 42732 6d61be152c55
equal deleted inserted replaced
42730:92ac6b1697a7 42731:5109217a9ab6
     5 #
     5 #
     6 # This software may be used and distributed according to the terms of the
     6 # This software may be used and distributed according to the terms of the
     7 # GNU General Public License version 2 or any later version.
     7 # GNU General Public License version 2 or any later version.
     8 
     8 
     9 from __future__ import absolute_import
     9 from __future__ import absolute_import
       
    10 
       
    11 from ..i18n import _
    10 
    12 
    11 from .constants import (
    13 from .constants import (
    12     REVIDX_DEFAULT_FLAGS,
    14     REVIDX_DEFAULT_FLAGS,
    13     REVIDX_ELLIPSIS,
    15     REVIDX_ELLIPSIS,
    14     REVIDX_EXTSTORED,
    16     REVIDX_EXTSTORED,
    16     REVIDX_ISCENSORED,
    18     REVIDX_ISCENSORED,
    17     REVIDX_RAWTEXT_CHANGING_FLAGS,
    19     REVIDX_RAWTEXT_CHANGING_FLAGS,
    18 )
    20 )
    19 
    21 
    20 from .. import (
    22 from .. import (
       
    23     error,
    21     util
    24     util
    22 )
    25 )
    23 
    26 
    24 # blanked usage of all the name to prevent pyflakes constraints
    27 # blanked usage of all the name to prevent pyflakes constraints
    25 # We need these name available in the module for extensions.
    28 # We need these name available in the module for extensions.
    35 # Store flag processors (cf. 'addflagprocessor()' to register)
    38 # Store flag processors (cf. 'addflagprocessor()' to register)
    36 flagprocessors = {
    39 flagprocessors = {
    37     REVIDX_ISCENSORED: None,
    40     REVIDX_ISCENSORED: None,
    38 }
    41 }
    39 
    42 
       
    43 def insertflagprocessor(flag, processor, flagprocessors):
       
    44     if not flag & REVIDX_KNOWN_FLAGS:
       
    45         msg = _("cannot register processor on unknown flag '%#x'.") % (flag)
       
    46         raise error.ProgrammingError(msg)
       
    47     if flag not in REVIDX_FLAGS_ORDER:
       
    48         msg = _("flag '%#x' undefined in REVIDX_FLAGS_ORDER.") % (flag)
       
    49         raise error.ProgrammingError(msg)
       
    50     if flag in flagprocessors:
       
    51         msg = _("cannot register multiple processors on flag '%#x'.") % (flag)
       
    52         raise error.Abort(msg)
       
    53     flagprocessors[flag] = processor