Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/revlogutils/flagutil.py @ 43077:687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Done with
python3.7 contrib/byteify-strings.py -i $(hg files 'set:mercurial/**.py - mercurial/thirdparty/** + hgext/**.py - hgext/fsmonitor/pywatchman/** - mercurial/__init__.py')
black -l 80 -t py33 -S $(hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**" - hgext/fsmonitor/pywatchman/**')
# skip-blame mass-reformatting only
Differential Revision: https://phab.mercurial-scm.org/D6972
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:48:39 -0400 |
parents | 2372284d9457 |
children | 2d6aea053153 |
comparison
equal
deleted
inserted
replaced
43076:2372284d9457 | 43077:687b865b95ad |
---|---|
68 insertflagprocessor(flag, processor, flagprocessors) | 68 insertflagprocessor(flag, processor, flagprocessors) |
69 | 69 |
70 | 70 |
71 def insertflagprocessor(flag, processor, flagprocessors): | 71 def insertflagprocessor(flag, processor, flagprocessors): |
72 if not flag & REVIDX_KNOWN_FLAGS: | 72 if not flag & REVIDX_KNOWN_FLAGS: |
73 msg = _("cannot register processor on unknown flag '%#x'.") % flag | 73 msg = _(b"cannot register processor on unknown flag '%#x'.") % flag |
74 raise error.ProgrammingError(msg) | 74 raise error.ProgrammingError(msg) |
75 if flag not in REVIDX_FLAGS_ORDER: | 75 if flag not in REVIDX_FLAGS_ORDER: |
76 msg = _("flag '%#x' undefined in REVIDX_FLAGS_ORDER.") % flag | 76 msg = _(b"flag '%#x' undefined in REVIDX_FLAGS_ORDER.") % flag |
77 raise error.ProgrammingError(msg) | 77 raise error.ProgrammingError(msg) |
78 if flag in flagprocessors: | 78 if flag in flagprocessors: |
79 msg = _("cannot register multiple processors on flag '%#x'.") % flag | 79 msg = _(b"cannot register multiple processors on flag '%#x'.") % flag |
80 raise error.Abort(msg) | 80 raise error.Abort(msg) |
81 flagprocessors[flag] = processor | 81 flagprocessors[flag] = processor |
82 | 82 |
83 | 83 |
84 def processflagswrite(revlog, text, flags, sidedata): | 84 def processflagswrite(revlog, text, flags, sidedata): |
95 | 95 |
96 Returns a 2-tuple of ``(text, validatehash)`` where ``text`` is the | 96 Returns a 2-tuple of ``(text, validatehash)`` where ``text`` is the |
97 processed text and ``validatehash`` is a bool indicating whether the | 97 processed text and ``validatehash`` is a bool indicating whether the |
98 returned text should be checked for hash integrity. | 98 returned text should be checked for hash integrity. |
99 """ | 99 """ |
100 return _processflagsfunc(revlog, text, flags, 'write', sidedata=sidedata)[ | 100 return _processflagsfunc(revlog, text, flags, b'write', sidedata=sidedata)[ |
101 :2 | 101 :2 |
102 ] | 102 ] |
103 | 103 |
104 | 104 |
105 def processflagsread(revlog, text, flags): | 105 def processflagsread(revlog, text, flags): |
118 | 118 |
119 Returns a 2-tuple of ``(text, validatehash)`` where ``text`` is the | 119 Returns a 2-tuple of ``(text, validatehash)`` where ``text`` is the |
120 processed text and ``validatehash`` is a bool indicating whether the | 120 processed text and ``validatehash`` is a bool indicating whether the |
121 returned text should be checked for hash integrity. | 121 returned text should be checked for hash integrity. |
122 """ | 122 """ |
123 return _processflagsfunc(revlog, text, flags, 'read') | 123 return _processflagsfunc(revlog, text, flags, b'read') |
124 | 124 |
125 | 125 |
126 def processflagsraw(revlog, text, flags): | 126 def processflagsraw(revlog, text, flags): |
127 """Inspect revision data flags to check is the content hash should be | 127 """Inspect revision data flags to check is the content hash should be |
128 validated. | 128 validated. |
137 | 137 |
138 Returns a 2-tuple of ``(text, validatehash)`` where ``text`` is the | 138 Returns a 2-tuple of ``(text, validatehash)`` where ``text`` is the |
139 processed text and ``validatehash`` is a bool indicating whether the | 139 processed text and ``validatehash`` is a bool indicating whether the |
140 returned text should be checked for hash integrity. | 140 returned text should be checked for hash integrity. |
141 """ | 141 """ |
142 return _processflagsfunc(revlog, text, flags, 'raw')[1] | 142 return _processflagsfunc(revlog, text, flags, b'raw')[1] |
143 | 143 |
144 | 144 |
145 def _processflagsfunc(revlog, text, flags, operation, sidedata=None): | 145 def _processflagsfunc(revlog, text, flags, operation, sidedata=None): |
146 """internal function to process flag on a revlog | 146 """internal function to process flag on a revlog |
147 | 147 |
148 This function is private to this module, code should never needs to call it | 148 This function is private to this module, code should never needs to call it |
149 directly.""" | 149 directly.""" |
150 # fast path: no flag processors will run | 150 # fast path: no flag processors will run |
151 if flags == 0: | 151 if flags == 0: |
152 return text, True, {} | 152 return text, True, {} |
153 if operation not in ('read', 'write', 'raw'): | 153 if operation not in (b'read', b'write', b'raw'): |
154 raise error.ProgrammingError(_("invalid '%s' operation") % operation) | 154 raise error.ProgrammingError(_(b"invalid '%s' operation") % operation) |
155 # Check all flags are known. | 155 # Check all flags are known. |
156 if flags & ~REVIDX_KNOWN_FLAGS: | 156 if flags & ~REVIDX_KNOWN_FLAGS: |
157 raise revlog._flagserrorclass( | 157 raise revlog._flagserrorclass( |
158 _("incompatible revision flag '%#x'") | 158 _(b"incompatible revision flag '%#x'") |
159 % (flags & ~REVIDX_KNOWN_FLAGS) | 159 % (flags & ~REVIDX_KNOWN_FLAGS) |
160 ) | 160 ) |
161 validatehash = True | 161 validatehash = True |
162 # Depending on the operation (read or write), the order might be | 162 # Depending on the operation (read or write), the order might be |
163 # reversed due to non-commutative transforms. | 163 # reversed due to non-commutative transforms. |
164 orderedflags = REVIDX_FLAGS_ORDER | 164 orderedflags = REVIDX_FLAGS_ORDER |
165 if operation == 'write': | 165 if operation == b'write': |
166 orderedflags = reversed(orderedflags) | 166 orderedflags = reversed(orderedflags) |
167 | 167 |
168 outsidedata = {} | 168 outsidedata = {} |
169 for flag in orderedflags: | 169 for flag in orderedflags: |
170 # If a flagprocessor has been registered for a known flag, apply the | 170 # If a flagprocessor has been registered for a known flag, apply the |
171 # related operation transform and update result tuple. | 171 # related operation transform and update result tuple. |
172 if flag & flags: | 172 if flag & flags: |
173 vhash = True | 173 vhash = True |
174 | 174 |
175 if flag not in revlog._flagprocessors: | 175 if flag not in revlog._flagprocessors: |
176 message = _("missing processor for flag '%#x'") % flag | 176 message = _(b"missing processor for flag '%#x'") % flag |
177 raise revlog._flagserrorclass(message) | 177 raise revlog._flagserrorclass(message) |
178 | 178 |
179 processor = revlog._flagprocessors[flag] | 179 processor = revlog._flagprocessors[flag] |
180 if processor is not None: | 180 if processor is not None: |
181 readtransform, writetransform, rawtransform = processor | 181 readtransform, writetransform, rawtransform = processor |
182 | 182 |
183 if operation == 'raw': | 183 if operation == b'raw': |
184 vhash = rawtransform(revlog, text) | 184 vhash = rawtransform(revlog, text) |
185 elif operation == 'read': | 185 elif operation == b'read': |
186 text, vhash, s = readtransform(revlog, text) | 186 text, vhash, s = readtransform(revlog, text) |
187 outsidedata.update(s) | 187 outsidedata.update(s) |
188 else: # write operation | 188 else: # write operation |
189 text, vhash = writetransform(revlog, text, sidedata) | 189 text, vhash = writetransform(revlog, text, sidedata) |
190 validatehash = validatehash and vhash | 190 validatehash = validatehash and vhash |