Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hook.py @ 14993:e5b2ee5157ae stable
hook: be prepared for __stdout/err__ not having fileno()
it may have been replaced, see https://bitbucket.org/tortoisehg/thg/issue/937
author | Idan Kamara <idankk86@gmail.com> |
---|---|
date | Sat, 30 Jul 2011 23:41:10 +0300 |
parents | 58f97dcbd550 |
children | f6a737357195 |
comparison
equal
deleted
inserted
replaced
14992:188936b334b1 | 14993:e5b2ee5157ae |
---|---|
132 def hook(ui, repo, name, throw=False, **args): | 132 def hook(ui, repo, name, throw=False, **args): |
133 r = False | 133 r = False |
134 | 134 |
135 oldstdout = -1 | 135 oldstdout = -1 |
136 if _redirect: | 136 if _redirect: |
137 stdoutno = sys.__stdout__.fileno() | 137 try: |
138 stderrno = sys.__stderr__.fileno() | 138 stdoutno = sys.__stdout__.fileno() |
139 # temporarily redirect stdout to stderr, if possible | 139 stderrno = sys.__stderr__.fileno() |
140 if stdoutno >= 0 and stderrno >= 0: | 140 # temporarily redirect stdout to stderr, if possible |
141 oldstdout = os.dup(stdoutno) | 141 if stdoutno >= 0 and stderrno >= 0: |
142 os.dup2(stderrno, stdoutno) | 142 oldstdout = os.dup(stdoutno) |
143 os.dup2(stderrno, stdoutno) | |
144 except AttributeError: | |
145 # __stdout/err__ doesn't have fileno(), it's not a real file | |
146 pass | |
143 | 147 |
144 try: | 148 try: |
145 for hname, cmd in ui.configitems('hooks'): | 149 for hname, cmd in ui.configitems('hooks'): |
146 if hname.split('.')[0] != name or not cmd: | 150 if hname.split('.')[0] != name or not cmd: |
147 continue | 151 continue |