comparison mercurial/revlogutils/flagutil.py @ 42732:6d61be152c55

flagutil: move addflagprocessor to the new module (API)
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 08 Aug 2019 01:59:43 +0200
parents 5109217a9ab6
children 5bb68fb72df2
comparison
equal deleted inserted replaced
42731:5109217a9ab6 42732:6d61be152c55
38 # Store flag processors (cf. 'addflagprocessor()' to register) 38 # Store flag processors (cf. 'addflagprocessor()' to register)
39 flagprocessors = { 39 flagprocessors = {
40 REVIDX_ISCENSORED: None, 40 REVIDX_ISCENSORED: None,
41 } 41 }
42 42
43 def addflagprocessor(flag, processor):
44 """Register a flag processor on a revision data flag.
45
46 Invariant:
47 - Flags need to be defined in REVIDX_KNOWN_FLAGS and REVIDX_FLAGS_ORDER,
48 and REVIDX_RAWTEXT_CHANGING_FLAGS if they can alter rawtext.
49 - Only one flag processor can be registered on a specific flag.
50 - flagprocessors must be 3-tuples of functions (read, write, raw) with the
51 following signatures:
52 - (read) f(self, rawtext) -> text, bool
53 - (write) f(self, text) -> rawtext, bool
54 - (raw) f(self, rawtext) -> bool
55 "text" is presented to the user. "rawtext" is stored in revlog data, not
56 directly visible to the user.
57 The boolean returned by these transforms is used to determine whether
58 the returned text can be used for hash integrity checking. For example,
59 if "write" returns False, then "text" is used to generate hash. If
60 "write" returns True, that basically means "rawtext" returned by "write"
61 should be used to generate hash. Usually, "write" and "read" return
62 different booleans. And "raw" returns a same boolean as "write".
63
64 Note: The 'raw' transform is used for changegroup generation and in some
65 debug commands. In this case the transform only indicates whether the
66 contents can be used for hash integrity checks.
67 """
68 insertflagprocessor(flag, processor, flagprocessors)
69
43 def insertflagprocessor(flag, processor, flagprocessors): 70 def insertflagprocessor(flag, processor, flagprocessors):
44 if not flag & REVIDX_KNOWN_FLAGS: 71 if not flag & REVIDX_KNOWN_FLAGS:
45 msg = _("cannot register processor on unknown flag '%#x'.") % (flag) 72 msg = _("cannot register processor on unknown flag '%#x'.") % (flag)
46 raise error.ProgrammingError(msg) 73 raise error.ProgrammingError(msg)
47 if flag not in REVIDX_FLAGS_ORDER: 74 if flag not in REVIDX_FLAGS_ORDER: