Patchwork D8526: py3: change default priority and length used for sorting hooks to be compatible with python 3

login
register
mail settings
Submitter phabricator
Date May 15, 2020, 3:18 a.m.
Message ID <differential-rev-PHID-DREV-w6qcevpl4da65u5dhhqd-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46314/
State Superseded
Headers show

Comments

phabricator - May 15, 2020, 3:18 a.m.
charlesetc created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D8526

AFFECTED FILES
  mercurial/hook.py

CHANGE DETAILS




To: charlesetc, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/hook.py b/mercurial/hook.py
--- a/mercurial/hook.py
+++ b/mercurial/hook.py
@@ -206,7 +206,7 @@ 
     # in that section uses "_fromuntrusted" as its command.
     untrustedhooks = _hookitems(ui, _untrusted=True)
     for name, value in untrustedhooks.items():
-        trustedvalue = hooks.get(name, (None, None, name, _fromuntrusted))
+        trustedvalue = hooks.get(name, ((), (), name, _fromuntrusted))
         if value != trustedvalue:
             (lp, lo, lk, lv) = trustedvalue
             hooks[name] = (lp, lo, lk, _fromuntrusted)
@@ -222,7 +222,7 @@ 
             continue
 
         priority = ui.configint(b'hooks', b'priority.%s' % name, 0)
-        hooks[name] = (-priority, len(hooks), name, cmd)
+        hooks[name] = ((-priority,), (len(hooks),), name, cmd)
     return hooks