comparison mercurial/hook.py @ 44828:50416d3d4b65 stable

py3: change default priority and length used for sorting hooks to be compatible with python 3 The call to `sorted(hooks.values())` can on line 213 of hooks.py can raise when using python 3. For instance, when hooks.values is `[(0, 2, b'post-commit.check-status', b''), (None, None, b'changegroup.app-hooks', <object object at 0x7f5279885590>)]`, the error is `TypeError: '<' not supported between instances of 'NoneType' and 'int'` This fix keeps the same order that was used in python 2 without relying on comparison with None. Differential Revision: https://phab.mercurial-scm.org/D8527
author Charles Chamberlain <cchamberlain@janestreet.com>
date Thu, 14 May 2020 23:14:24 -0400
parents 3cbbfd0bfc17
children fd3b94f1712d
comparison
equal deleted inserted replaced
44827:f445a4f7e8a7 44828:50416d3d4b65
204 # Be careful in this section, propagating the real commands from untrusted 204 # Be careful in this section, propagating the real commands from untrusted
205 # sources would create a security vulnerability, make sure anything altered 205 # sources would create a security vulnerability, make sure anything altered
206 # in that section uses "_fromuntrusted" as its command. 206 # in that section uses "_fromuntrusted" as its command.
207 untrustedhooks = _hookitems(ui, _untrusted=True) 207 untrustedhooks = _hookitems(ui, _untrusted=True)
208 for name, value in untrustedhooks.items(): 208 for name, value in untrustedhooks.items():
209 trustedvalue = hooks.get(name, (None, None, name, _fromuntrusted)) 209 trustedvalue = hooks.get(name, ((), (), name, _fromuntrusted))
210 if value != trustedvalue: 210 if value != trustedvalue:
211 (lp, lo, lk, lv) = trustedvalue 211 (lp, lo, lk, lv) = trustedvalue
212 hooks[name] = (lp, lo, lk, _fromuntrusted) 212 hooks[name] = (lp, lo, lk, _fromuntrusted)
213 # (end of the security sensitive section) 213 # (end of the security sensitive section)
214 return [(k, v) for p, o, k, v in sorted(hooks.values())] 214 return [(k, v) for p, o, k, v in sorted(hooks.values())]
220 for name, cmd in ui.configitems(b'hooks', untrusted=_untrusted): 220 for name, cmd in ui.configitems(b'hooks', untrusted=_untrusted):
221 if name.startswith(b'priority.') or name.startswith(b'tonative.'): 221 if name.startswith(b'priority.') or name.startswith(b'tonative.'):
222 continue 222 continue
223 223
224 priority = ui.configint(b'hooks', b'priority.%s' % name, 0) 224 priority = ui.configint(b'hooks', b'priority.%s' % name, 0)
225 hooks[name] = (-priority, len(hooks), name, cmd) 225 hooks[name] = ((-priority,), (len(hooks),), name, cmd)
226 return hooks 226 return hooks
227 227
228 228
229 _redirect = False 229 _redirect = False
230 230