comparison mercurial/revlogutils/flagutil.py @ 46709:3d740058b467

sidedata: move to new sidedata storage in revlogv2 The current (experimental) sidedata system uses flagprocessors to signify the presence and store/retrieve sidedata from the raw revlog data. This proved to be quite fragile from an exchange perspective and a lot more complex than simply having a dedicated space in the new revlog format. This change does not handle exchange (ironically), so the test for amend - that uses a bundle - is broken. This functionality is split into the next patches. Differential Revision: https://phab.mercurial-scm.org/D9993
author Raphaël Gomès <rgomes@octobus.net>
date Mon, 18 Jan 2021 11:44:51 +0100
parents 2d6aea053153
children 119790e1c67c
comparison
equal deleted inserted replaced
46708:358737abeeef 46709:3d740058b467
82 msg = _(b"cannot register multiple processors on flag '%#x'.") % flag 82 msg = _(b"cannot register multiple processors on flag '%#x'.") % flag
83 raise error.Abort(msg) 83 raise error.Abort(msg)
84 flagprocessors[flag] = processor 84 flagprocessors[flag] = processor
85 85
86 86
87 def processflagswrite(revlog, text, flags, sidedata): 87 def processflagswrite(revlog, text, flags):
88 """Inspect revision data flags and applies write transformations defined 88 """Inspect revision data flags and applies write transformations defined
89 by registered flag processors. 89 by registered flag processors.
90 90
91 ``text`` - the revision data to process 91 ``text`` - the revision data to process
92 ``flags`` - the revision flags 92 ``flags`` - the revision flags
98 98
99 Returns a 2-tuple of ``(text, validatehash)`` where ``text`` is the 99 Returns a 2-tuple of ``(text, validatehash)`` where ``text`` is the
100 processed text and ``validatehash`` is a bool indicating whether the 100 processed text and ``validatehash`` is a bool indicating whether the
101 returned text should be checked for hash integrity. 101 returned text should be checked for hash integrity.
102 """ 102 """
103 return _processflagsfunc(revlog, text, flags, b'write', sidedata=sidedata)[ 103 return _processflagsfunc(
104 :2 104 revlog,
105 ] 105 text,
106 flags,
107 b'write',
108 )[:2]
106 109
107 110
108 def processflagsread(revlog, text, flags): 111 def processflagsread(revlog, text, flags):
109 """Inspect revision data flags and applies read transformations defined 112 """Inspect revision data flags and applies read transformations defined
110 by registered flag processors. 113 by registered flag processors.
143 returned text should be checked for hash integrity. 146 returned text should be checked for hash integrity.
144 """ 147 """
145 return _processflagsfunc(revlog, text, flags, b'raw')[1] 148 return _processflagsfunc(revlog, text, flags, b'raw')[1]
146 149
147 150
148 def _processflagsfunc(revlog, text, flags, operation, sidedata=None): 151 def _processflagsfunc(revlog, text, flags, operation):
149 """internal function to process flag on a revlog 152 """internal function to process flag on a revlog
150 153
151 This function is private to this module, code should never needs to call it 154 This function is private to this module, code should never needs to call it
152 directly.""" 155 directly."""
153 # fast path: no flag processors will run 156 # fast path: no flag processors will run
154 if flags == 0: 157 if flags == 0:
155 return text, True, {} 158 return text, True
156 if operation not in (b'read', b'write', b'raw'): 159 if operation not in (b'read', b'write', b'raw'):
157 raise error.ProgrammingError(_(b"invalid '%s' operation") % operation) 160 raise error.ProgrammingError(_(b"invalid '%s' operation") % operation)
158 # Check all flags are known. 161 # Check all flags are known.
159 if flags & ~REVIDX_KNOWN_FLAGS: 162 if flags & ~REVIDX_KNOWN_FLAGS:
160 raise revlog._flagserrorclass( 163 raise revlog._flagserrorclass(
166 # reversed due to non-commutative transforms. 169 # reversed due to non-commutative transforms.
167 orderedflags = REVIDX_FLAGS_ORDER 170 orderedflags = REVIDX_FLAGS_ORDER
168 if operation == b'write': 171 if operation == b'write':
169 orderedflags = reversed(orderedflags) 172 orderedflags = reversed(orderedflags)
170 173
171 outsidedata = {}
172 for flag in orderedflags: 174 for flag in orderedflags:
173 # If a flagprocessor has been registered for a known flag, apply the 175 # If a flagprocessor has been registered for a known flag, apply the
174 # related operation transform and update result tuple. 176 # related operation transform and update result tuple.
175 if flag & flags: 177 if flag & flags:
176 vhash = True 178 vhash = True
184 readtransform, writetransform, rawtransform = processor 186 readtransform, writetransform, rawtransform = processor
185 187
186 if operation == b'raw': 188 if operation == b'raw':
187 vhash = rawtransform(revlog, text) 189 vhash = rawtransform(revlog, text)
188 elif operation == b'read': 190 elif operation == b'read':
189 text, vhash, s = readtransform(revlog, text) 191 text, vhash = readtransform(revlog, text)
190 outsidedata.update(s)
191 else: # write operation 192 else: # write operation
192 text, vhash = writetransform(revlog, text, sidedata) 193 text, vhash = writetransform(revlog, text)
193 validatehash = validatehash and vhash 194 validatehash = validatehash and vhash
194 195
195 return text, validatehash, outsidedata 196 return text, validatehash