Mercurial > public > mercurial-scm > hg
comparison mercurial/revlogutils/flagutil.py @ 42875:87a934684c3b
flagprocessors: introduce specialized functions
This make the call site clearer and the open the way to more diverse return
types.
For now, the same old code is still in use under the hood.
Differential Revision: https://phab.mercurial-scm.org/D6800
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 30 Aug 2019 18:54:36 +0200 |
parents | 7907008a0bb5 |
children | 519b45603880 |
comparison
equal
deleted
inserted
replaced
42874:705428da231f | 42875:87a934684c3b |
---|---|
88 """ | 88 """ |
89 | 89 |
90 _flagserrorclass = error.RevlogError | 90 _flagserrorclass = error.RevlogError |
91 | 91 |
92 def _processflags(self, text, flags, operation, raw=False): | 92 def _processflags(self, text, flags, operation, raw=False): |
93 """Inspect revision data flags and applies transforms defined by | 93 """deprecated entry point to access flag processors""" |
94 registered flag processors. | 94 if raw: |
95 return text, self._processflagsraw(text, flags) | |
96 elif operation == 'read': | |
97 return self._processflagsread(text, flags) | |
98 else: # write operation | |
99 return self._processflagswrite(text, flags) | |
100 | |
101 def _processflagsread(self, text, flags): | |
102 """Inspect revision data flags and applies read transformations defined | |
103 by registered flag processors. | |
95 | 104 |
96 ``text`` - the revision data to process | 105 ``text`` - the revision data to process |
97 ``flags`` - the revision flags | 106 ``flags`` - the revision flags |
98 ``operation`` - the operation being performed (read or write) | |
99 ``raw`` - an optional argument describing if the raw transform should be | 107 ``raw`` - an optional argument describing if the raw transform should be |
100 applied. | 108 applied. |
101 | 109 |
102 This method processes the flags in the order (or reverse order if | 110 This method processes the flags in the order (or reverse order if |
103 ``operation`` is 'write') defined by REVIDX_FLAGS_ORDER, applying the | 111 ``operation`` is 'write') defined by REVIDX_FLAGS_ORDER, applying the |
105 in REVIDX_FLAGS_ORDER needs to be stable to allow non-commutativity. | 113 in REVIDX_FLAGS_ORDER needs to be stable to allow non-commutativity. |
106 | 114 |
107 Returns a 2-tuple of ``(text, validatehash)`` where ``text`` is the | 115 Returns a 2-tuple of ``(text, validatehash)`` where ``text`` is the |
108 processed text and ``validatehash`` is a bool indicating whether the | 116 processed text and ``validatehash`` is a bool indicating whether the |
109 returned text should be checked for hash integrity. | 117 returned text should be checked for hash integrity. |
118 """ | |
119 return self._processflagsfunc(text, flags, 'read') | |
110 | 120 |
111 Note: If the ``raw`` argument is set, it has precedence over the | 121 def _processflagswrite(self, text, flags): |
112 operation and will only update the value of ``validatehash``. | 122 """Inspect revision data flags and applies write transformations defined |
123 by registered flag processors. | |
124 | |
125 ``text`` - the revision data to process | |
126 ``flags`` - the revision flags | |
127 | |
128 This method processes the flags in the order (or reverse order if | |
129 ``operation`` is 'write') defined by REVIDX_FLAGS_ORDER, applying the | |
130 flag processors registered for present flags. The order of flags defined | |
131 in REVIDX_FLAGS_ORDER needs to be stable to allow non-commutativity. | |
132 | |
133 Returns a 2-tuple of ``(text, validatehash)`` where ``text`` is the | |
134 processed text and ``validatehash`` is a bool indicating whether the | |
135 returned text should be checked for hash integrity. | |
113 """ | 136 """ |
137 return self._processflagsfunc(text, flags, 'write') | |
138 | |
139 def _processflagsraw(self, text, flags): | |
140 """Inspect revision data flags to check is the content hash should be | |
141 validated. | |
142 | |
143 ``text`` - the revision data to process | |
144 ``flags`` - the revision flags | |
145 | |
146 This method processes the flags in the order (or reverse order if | |
147 ``operation`` is 'write') defined by REVIDX_FLAGS_ORDER, applying the | |
148 flag processors registered for present flags. The order of flags defined | |
149 in REVIDX_FLAGS_ORDER needs to be stable to allow non-commutativity. | |
150 | |
151 Returns a 2-tuple of ``(text, validatehash)`` where ``text`` is the | |
152 processed text and ``validatehash`` is a bool indicating whether the | |
153 returned text should be checked for hash integrity. | |
154 """ | |
155 return self._processflagsfunc(text, flags, 'read', raw=True)[1] | |
156 | |
157 def _processflagsfunc(self, text, flags, operation, raw=False): | |
114 # fast path: no flag processors will run | 158 # fast path: no flag processors will run |
115 if flags == 0: | 159 if flags == 0: |
116 return text, True | 160 return text, True |
117 if not operation in ('read', 'write'): | 161 if not operation in ('read', 'write'): |
118 raise error.ProgrammingError(_("invalid '%s' operation") % | 162 raise error.ProgrammingError(_("invalid '%s' operation") % |