Mercurial > public > mercurial-scm > hg
comparison mercurial/revlogutils/flagutil.py @ 42731:5109217a9ab6
flagutil: move insertflagprocessor to the new module (API)
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 08 Aug 2019 01:25:37 +0200 |
parents | 92ac6b1697a7 |
children | 6d61be152c55 |
comparison
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 |