Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hook.py @ 30995:22fbca1d11ed
mercurial: switch to util.timer for all interval timings
util.timer is now the best available interval timer, at the expense of not
having a known epoch. Let's use it whenever the epoch is irrelevant.
author | Simon Farnsworth <simonfar@fb.com> |
---|---|
date | Wed, 15 Feb 2017 13:17:39 -0800 |
parents | 20a42325fdef |
children | a48c6ac5c13a |
comparison
equal
deleted
inserted
replaced
30994:ae5d60bb70c9 | 30995:22fbca1d11ed |
---|---|
7 | 7 |
8 from __future__ import absolute_import | 8 from __future__ import absolute_import |
9 | 9 |
10 import os | 10 import os |
11 import sys | 11 import sys |
12 import time | |
13 | 12 |
14 from .i18n import _ | 13 from .i18n import _ |
15 from . import ( | 14 from . import ( |
16 demandimport, | 15 demandimport, |
17 error, | 16 error, |
86 raise error.HookLoadError( | 85 raise error.HookLoadError( |
87 _('%s hook is invalid: "%s" is not callable') | 86 _('%s hook is invalid: "%s" is not callable') |
88 % (hname, funcname)) | 87 % (hname, funcname)) |
89 | 88 |
90 ui.note(_("calling hook %s: %s\n") % (hname, funcname)) | 89 ui.note(_("calling hook %s: %s\n") % (hname, funcname)) |
91 starttime = time.time() | 90 starttime = util.timer() |
92 | 91 |
93 try: | 92 try: |
94 r = obj(ui=ui, repo=repo, hooktype=name, **args) | 93 r = obj(ui=ui, repo=repo, hooktype=name, **args) |
95 except Exception as exc: | 94 except Exception as exc: |
96 if isinstance(exc, error.Abort): | 95 if isinstance(exc, error.Abort): |
104 if not ui.tracebackflag: | 103 if not ui.tracebackflag: |
105 ui.warn(_('(run with --traceback for stack trace)\n')) | 104 ui.warn(_('(run with --traceback for stack trace)\n')) |
106 ui.traceback() | 105 ui.traceback() |
107 return True, True | 106 return True, True |
108 finally: | 107 finally: |
109 duration = time.time() - starttime | 108 duration = util.timer() - starttime |
110 ui.log('pythonhook', 'pythonhook-%s: %s finished in %0.2f seconds\n', | 109 ui.log('pythonhook', 'pythonhook-%s: %s finished in %0.2f seconds\n', |
111 name, funcname, duration) | 110 name, funcname, duration) |
112 if r: | 111 if r: |
113 if throw: | 112 if throw: |
114 raise error.HookAbort(_('%s hook failed') % hname) | 113 raise error.HookAbort(_('%s hook failed') % hname) |
116 return r, False | 115 return r, False |
117 | 116 |
118 def _exthook(ui, repo, name, cmd, args, throw): | 117 def _exthook(ui, repo, name, cmd, args, throw): |
119 ui.note(_("running hook %s: %s\n") % (name, cmd)) | 118 ui.note(_("running hook %s: %s\n") % (name, cmd)) |
120 | 119 |
121 starttime = time.time() | 120 starttime = util.timer() |
122 env = {} | 121 env = {} |
123 | 122 |
124 # make in-memory changes visible to external process | 123 # make in-memory changes visible to external process |
125 if repo is not None: | 124 if repo is not None: |
126 tr = repo.currenttransaction() | 125 tr = repo.currenttransaction() |
143 cwd = repo.root | 142 cwd = repo.root |
144 else: | 143 else: |
145 cwd = pycompat.getcwd() | 144 cwd = pycompat.getcwd() |
146 r = ui.system(cmd, environ=env, cwd=cwd) | 145 r = ui.system(cmd, environ=env, cwd=cwd) |
147 | 146 |
148 duration = time.time() - starttime | 147 duration = util.timer() - starttime |
149 ui.log('exthook', 'exthook-%s: %s finished in %0.2f seconds\n', | 148 ui.log('exthook', 'exthook-%s: %s finished in %0.2f seconds\n', |
150 name, cmd, duration) | 149 name, cmd, duration) |
151 if r: | 150 if r: |
152 desc, r = util.explainexit(r) | 151 desc, r = util.explainexit(r) |
153 if throw: | 152 if throw: |