Show More
@@ -655,7 +655,10 b' Commands or Python functions that get au' | |||||
655 | various actions such as starting or finishing a commit. Multiple |
|
655 | various actions such as starting or finishing a commit. Multiple | |
656 | hooks can be run for the same action by appending a suffix to the |
|
656 | hooks can be run for the same action by appending a suffix to the | |
657 | action. Overriding a site-wide hook can be done by changing its |
|
657 | action. Overriding a site-wide hook can be done by changing its | |
658 | value or setting it to an empty string. |
|
658 | value or setting it to an empty string. Hooks can be prioritized | |
|
659 | by adding a prefix of ``priority`` to the hook name on a new line | |||
|
660 | and setting the priority. The default priority is 0 if | |||
|
661 | not specified. | |||
659 |
|
662 | |||
660 | Example ``.hg/hgrc``:: |
|
663 | Example ``.hg/hgrc``:: | |
661 |
|
664 | |||
@@ -666,6 +669,8 b' Example ``.hg/hgrc``::' | |||||
666 | incoming = |
|
669 | incoming = | |
667 | incoming.email = /my/email/hook |
|
670 | incoming.email = /my/email/hook | |
668 | incoming.autobuild = /my/build/hook |
|
671 | incoming.autobuild = /my/build/hook | |
|
672 | # force autobuild hook to run before other incoming hooks | |||
|
673 | priority.incoming.autobuild = 1 | |||
669 |
|
674 | |||
670 | Most hooks are run with environment variables set that give useful |
|
675 | Most hooks are run with environment variables set that give useful | |
671 | additional information. For each hook below, the environment |
|
676 | additional information. For each hook below, the environment |
@@ -124,6 +124,14 b' def _exthook(ui, repo, name, cmd, args, ' | |||||
124 | ui.warn(_('warning: %s hook %s\n') % (name, desc)) |
|
124 | ui.warn(_('warning: %s hook %s\n') % (name, desc)) | |
125 | return r |
|
125 | return r | |
126 |
|
126 | |||
|
127 | def _allhooks(ui): | |||
|
128 | hooks = [] | |||
|
129 | for name, cmd in ui.configitems('hooks'): | |||
|
130 | if not name.startswith('priority'): | |||
|
131 | priority = ui.configint('hooks', 'priority.%s' % name, 0) | |||
|
132 | hooks.append((-priority, len(hooks), name, cmd)) | |||
|
133 | return [(k, v) for p, o, k, v in sorted(hooks)] | |||
|
134 | ||||
127 | _redirect = False |
|
135 | _redirect = False | |
128 | def redirect(state): |
|
136 | def redirect(state): | |
129 | global _redirect |
|
137 | global _redirect | |
@@ -147,7 +155,7 b' def hook(ui, repo, name, throw=False, **' | |||||
147 | pass |
|
155 | pass | |
148 |
|
156 | |||
149 | try: |
|
157 | try: | |
150 |
for hname, cmd in ui |
|
158 | for hname, cmd in _allhooks(ui): | |
151 | if hname.split('.')[0] != name or not cmd: |
|
159 | if hname.split('.')[0] != name or not cmd: | |
152 | continue |
|
160 | continue | |
153 | if util.safehasattr(cmd, '__call__'): |
|
161 | if util.safehasattr(cmd, '__call__'): |
@@ -553,3 +553,19 b' that is passed to pre/post hooks' | |||||
553 | calling hook pre-identify: hooktests.verbosehook |
|
553 | calling hook pre-identify: hooktests.verbosehook | |
554 | verbose output from hook |
|
554 | verbose output from hook | |
555 | cb9a9f314b8b |
|
555 | cb9a9f314b8b | |
|
556 | ||||
|
557 | Ensure hooks can be prioritized | |||
|
558 | ||||
|
559 | $ echo '[hooks]' > .hg/hgrc | |||
|
560 | $ echo 'pre-identify.a = python:hooktests.verbosehook' >> .hg/hgrc | |||
|
561 | $ echo 'pre-identify.b = python:hooktests.verbosehook' >> .hg/hgrc | |||
|
562 | $ echo 'priority.pre-identify.b = 1' >> .hg/hgrc | |||
|
563 | $ echo 'pre-identify.c = python:hooktests.verbosehook' >> .hg/hgrc | |||
|
564 | $ hg id --verbose | |||
|
565 | calling hook pre-identify.b: hooktests.verbosehook | |||
|
566 | verbose output from hook | |||
|
567 | calling hook pre-identify.a: hooktests.verbosehook | |||
|
568 | verbose output from hook | |||
|
569 | calling hook pre-identify.c: hooktests.verbosehook | |||
|
570 | verbose output from hook | |||
|
571 | cb9a9f314b8b |
General Comments 0
You need to be logged in to leave comments.
Login now