Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hook.py @ 26737:a930d66a04af
hook: factor out determination of hooks from running them
This will allow other code to run a predetermined series of hooks.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Wed, 14 Oct 2015 16:13:31 -0700 |
parents | 8d1cfd77b64f |
children | 9abc2c921bbd |
comparison
equal
deleted
inserted
replaced
26736:143b52fce68e | 26737:a930d66a04af |
---|---|
160 | 160 |
161 def hook(ui, repo, name, throw=False, **args): | 161 def hook(ui, repo, name, throw=False, **args): |
162 if not ui.callhooks: | 162 if not ui.callhooks: |
163 return False | 163 return False |
164 | 164 |
165 hooks = [] | |
166 for hname, cmd in _allhooks(ui): | |
167 if hname.split('.')[0] == name and cmd: | |
168 hooks.append((hname, cmd)) | |
169 | |
170 return runhooks(ui, repo, name, hooks, throw=throw, **args) | |
171 | |
172 def runhooks(ui, repo, name, hooks, throw=False, **args): | |
165 r = False | 173 r = False |
166 oldstdout = -1 | 174 oldstdout = -1 |
167 | 175 |
168 try: | 176 try: |
169 for hname, cmd in _allhooks(ui): | 177 for hname, cmd in hooks: |
170 if hname.split('.')[0] != name or not cmd: | |
171 continue | |
172 | |
173 if oldstdout == -1 and _redirect: | 178 if oldstdout == -1 and _redirect: |
174 try: | 179 try: |
175 stdoutno = sys.__stdout__.fileno() | 180 stdoutno = sys.__stdout__.fileno() |
176 stderrno = sys.__stderr__.fileno() | 181 stderrno = sys.__stderr__.fileno() |
177 # temporarily redirect stdout to stderr, if possible | 182 # temporarily redirect stdout to stderr, if possible |