comparison mercurial/revlogutils/flagutil.py @ 42984:66dc5a522f37

flagprocessors: return flagdata in the main processing function This function input and return are becoming stranger and stranger bnut I don't have a good plan to make is saner without problematic code duplication, so it will be this way to now. Differential Revision: https://phab.mercurial-scm.org/D6812
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 04 Sep 2019 00:13:45 +0200
parents a45d670c2bfc
children bd5858c28bbe
comparison
equal deleted inserted replaced
42983:a45d670c2bfc 42984:66dc5a522f37
116 116
117 Returns a 2-tuple of ``(text, validatehash)`` where ``text`` is the 117 Returns a 2-tuple of ``(text, validatehash)`` where ``text`` is the
118 processed text and ``validatehash`` is a bool indicating whether the 118 processed text and ``validatehash`` is a bool indicating whether the
119 returned text should be checked for hash integrity. 119 returned text should be checked for hash integrity.
120 """ 120 """
121 text, vhash = self._processflagsfunc(text, flags, 'read') 121 return self._processflagsfunc(text, flags, 'read')
122 return text, vhash, {}
123 122
124 def _processflagswrite(self, text, flags): 123 def _processflagswrite(self, text, flags):
125 """Inspect revision data flags and applies write transformations defined 124 """Inspect revision data flags and applies write transformations defined
126 by registered flag processors. 125 by registered flag processors.
127 126
135 134
136 Returns a 2-tuple of ``(text, validatehash)`` where ``text`` is the 135 Returns a 2-tuple of ``(text, validatehash)`` where ``text`` is the
137 processed text and ``validatehash`` is a bool indicating whether the 136 processed text and ``validatehash`` is a bool indicating whether the
138 returned text should be checked for hash integrity. 137 returned text should be checked for hash integrity.
139 """ 138 """
140 return self._processflagsfunc(text, flags, 'write') 139 return self._processflagsfunc(text, flags, 'write')[:2]
141 140
142 def _processflagsraw(self, text, flags): 141 def _processflagsraw(self, text, flags):
143 """Inspect revision data flags to check is the content hash should be 142 """Inspect revision data flags to check is the content hash should be
144 validated. 143 validated.
145 144
158 return self._processflagsfunc(text, flags, 'raw')[1] 157 return self._processflagsfunc(text, flags, 'raw')[1]
159 158
160 def _processflagsfunc(self, text, flags, operation): 159 def _processflagsfunc(self, text, flags, operation):
161 # fast path: no flag processors will run 160 # fast path: no flag processors will run
162 if flags == 0: 161 if flags == 0:
163 return text, True 162 return text, True, {}
164 if operation not in ('read', 'write', 'raw'): 163 if operation not in ('read', 'write', 'raw'):
165 raise error.ProgrammingError(_("invalid '%s' operation") % 164 raise error.ProgrammingError(_("invalid '%s' operation") %
166 operation) 165 operation)
167 # Check all flags are known. 166 # Check all flags are known.
168 if flags & ~REVIDX_KNOWN_FLAGS: 167 if flags & ~REVIDX_KNOWN_FLAGS:
173 # reversed due to non-commutative transforms. 172 # reversed due to non-commutative transforms.
174 orderedflags = REVIDX_FLAGS_ORDER 173 orderedflags = REVIDX_FLAGS_ORDER
175 if operation == 'write': 174 if operation == 'write':
176 orderedflags = reversed(orderedflags) 175 orderedflags = reversed(orderedflags)
177 176
177 outsidedata = {}
178 for flag in orderedflags: 178 for flag in orderedflags:
179 # If a flagprocessor has been registered for a known flag, apply the 179 # If a flagprocessor has been registered for a known flag, apply the
180 # related operation transform and update result tuple. 180 # related operation transform and update result tuple.
181 if flag & flags: 181 if flag & flags:
182 vhash = True 182 vhash = True
195 text, vhash = readtransform(self, text) 195 text, vhash = readtransform(self, text)
196 else: # write operation 196 else: # write operation
197 text, vhash = writetransform(self, text) 197 text, vhash = writetransform(self, text)
198 validatehash = validatehash and vhash 198 validatehash = validatehash and vhash
199 199
200 return text, validatehash 200 return text, validatehash, outsidedata