Show More
@@ -65,6 +65,12 b' def _pythonhook(ui, repo, name, hname, f' | |||||
65 | '("%s" is not callable)') % |
|
65 | '("%s" is not callable)') % | |
66 | (hname, funcname)) |
|
66 | (hname, funcname)) | |
67 | try: |
|
67 | try: | |
|
68 | # redirect IO descriptors the the ui descriptors so hooks that write | |||
|
69 | # directly to these don't mess the command protocol when running through | |||
|
70 | # the command server | |||
|
71 | old = sys.stdout, sys.stderr, sys.stdin | |||
|
72 | sys.stdout, sys.stderr, sys.stdin = ui.fout, ui.ferr, ui.fin | |||
|
73 | ||||
68 | r = obj(ui=ui, repo=repo, hooktype=name, **args) |
|
74 | r = obj(ui=ui, repo=repo, hooktype=name, **args) | |
69 | except KeyboardInterrupt: |
|
75 | except KeyboardInterrupt: | |
70 | raise |
|
76 | raise | |
@@ -79,6 +85,8 b' def _pythonhook(ui, repo, name, hname, f' | |||||
79 | raise |
|
85 | raise | |
80 | ui.traceback() |
|
86 | ui.traceback() | |
81 | return True |
|
87 | return True | |
|
88 | finally: | |||
|
89 | sys.stdout, sys.stderr, sys.stdin = old | |||
82 | if r: |
|
90 | if r: | |
83 | if throw: |
|
91 | if throw: | |
84 | raise util.Abort(_('%s hook failed') % hname) |
|
92 | raise util.Abort(_('%s hook failed') % hname) |
@@ -144,6 +144,16 b' def localhgrc(server):' | |||||
144 | runcommand(server, ['-R', 'foo', 'showconfig']) |
|
144 | runcommand(server, ['-R', 'foo', 'showconfig']) | |
145 | shutil.rmtree('foo') |
|
145 | shutil.rmtree('foo') | |
146 |
|
146 | |||
|
147 | def hook(**args): | |||
|
148 | print 'hook talking' | |||
|
149 | print 'now try to read something: %r' % sys.stdin.read() | |||
|
150 | ||||
|
151 | def hookoutput(server): | |||
|
152 | readchannel(server) | |||
|
153 | runcommand(server, ['--config', | |||
|
154 | 'hooks.pre-identify=python:test-commandserver.hook', 'id'], | |||
|
155 | input=cStringIO.StringIO('some input')) | |||
|
156 | ||||
147 | if __name__ == '__main__': |
|
157 | if __name__ == '__main__': | |
148 | os.system('hg init') |
|
158 | os.system('hg init') | |
149 |
|
159 | |||
@@ -158,3 +168,4 b" if __name__ == '__main__':" | |||||
158 | hgrc.write('[ui]\nfoo=bar\n') |
|
168 | hgrc.write('[ui]\nfoo=bar\n') | |
159 | hgrc.close() |
|
169 | hgrc.close() | |
160 | check(localhgrc) |
|
170 | check(localhgrc) | |
|
171 | check(hookoutput) |
General Comments 0
You need to be logged in to leave comments.
Login now