Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hook.py @ 7416:196b05a548d0
hooks: restore io correctly on exception
author | Jesse Long <jesse@virtualpostman.co.za> |
---|---|
date | Tue, 25 Nov 2008 16:40:54 -0600 |
parents | 810ca383da9c |
children | 182b7114d35a |
comparison
equal
deleted
inserted
replaced
7415:6163ef936a00 | 7416:196b05a548d0 |
---|---|
94 if _redirect: | 94 if _redirect: |
95 # temporarily redirect stdout to stderr | 95 # temporarily redirect stdout to stderr |
96 oldstdout = os.dup(sys.__stdout__.fileno()) | 96 oldstdout = os.dup(sys.__stdout__.fileno()) |
97 os.dup2(sys.__stderr__.fileno(), sys.__stdout__.fileno()) | 97 os.dup2(sys.__stderr__.fileno(), sys.__stdout__.fileno()) |
98 | 98 |
99 for hname, cmd in util.sort(ui.configitems('hooks')): | 99 try: |
100 if hname.split('.')[0] != name or not cmd: | 100 for hname, cmd in util.sort(ui.configitems('hooks')): |
101 continue | 101 if hname.split('.')[0] != name or not cmd: |
102 if callable(cmd): | 102 continue |
103 r = _pythonhook(ui, repo, name, hname, cmd, args, throw) or r | 103 if callable(cmd): |
104 elif cmd.startswith('python:'): | 104 r = _pythonhook(ui, repo, name, hname, cmd, args, throw) or r |
105 r = _pythonhook(ui, repo, name, hname, cmd[7:].strip(), | 105 elif cmd.startswith('python:'): |
106 args, throw) or r | 106 r = _pythonhook(ui, repo, name, hname, cmd[7:].strip(), |
107 else: | 107 args, throw) or r |
108 r = _exthook(ui, repo, hname, cmd, args, throw) or r | 108 else: |
109 | 109 r = _exthook(ui, repo, hname, cmd, args, throw) or r |
110 if _redirect: | 110 finally: |
111 os.dup2(oldstdout, sys.__stdout__.fileno()) | 111 if _redirect: |
112 os.close(oldstdout) | 112 os.dup2(oldstdout, sys.__stdout__.fileno()) |
113 os.close(oldstdout) | |
113 | 114 |
114 return r | 115 return r |