# HG changeset patch # User Maxim Khitrov # Date 1277939723 18000 # Node ID c37f35d7f2f5abcd19ab0383345a9854f7831bf0 # Parent 1c1126b1d919b140bfee8721985ff134c6485acb http: deliver hook output to client diff -r 1c1126b1d919 -r c37f35d7f2f5 mercurial/hook.py --- a/mercurial/hook.py Wed Jun 23 13:44:07 2010 +0200 +++ b/mercurial/hook.py Wed Jun 30 18:15:23 2010 -0500 @@ -98,7 +98,10 @@ cwd = repo.root else: cwd = os.getcwd() - r = util.system(cmd, environ=env, cwd=cwd) + if 'HG_URL' in env and env['HG_URL'].startswith('remote:http'): + r = util.system(cmd, environ=env, cwd=cwd, out=ui) + else: + r = util.system(cmd, environ=env, cwd=cwd) if r: desc, r = util.explain_exit(r) if throw: diff -r 1c1126b1d919 -r c37f35d7f2f5 mercurial/util.py --- a/mercurial/util.py Wed Jun 23 13:44:07 2010 +0200 +++ b/mercurial/util.py Wed Jun 30 18:15:23 2010 -0500 @@ -366,13 +366,16 @@ global _hgexecutable _hgexecutable = path -def system(cmd, environ={}, cwd=None, onerr=None, errprefix=None): +def system(cmd, environ={}, cwd=None, onerr=None, errprefix=None, out=None): '''enhanced shell command execution. run with environment maybe modified, maybe in different dir. if command fails and onerr is None, return status. if ui object, print error message and return status, else raise onerr object as - exception.''' + exception. + + if out is specified, it is assumed to be a file-like object that has a + write() method. stdout and stderr will be redirected to out.''' def py2shell(val): 'convert python object into string that is useful to shell' if val is None or val is False: @@ -386,8 +389,17 @@ env = dict(os.environ) env.update((k, py2shell(v)) for k, v in environ.iteritems()) env['HG'] = hgexecutable() - rc = subprocess.call(cmd, shell=True, close_fds=closefds, - env=env, cwd=cwd) + if out is None: + rc = subprocess.call(cmd, shell=True, close_fds=closefds, + env=env, cwd=cwd) + else: + proc = subprocess.Popen(cmd, shell=True, close_fds=closefds, + env=env, cwd=cwd, stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) + for line in proc.stdout: + out.write(line) + proc.wait() + rc = proc.returncode if sys.platform == 'OpenVMS' and rc & 1: rc = 0 if rc and onerr: diff -r 1c1126b1d919 -r c37f35d7f2f5 tests/test-push-http --- a/tests/test-push-http Wed Jun 23 13:44:07 2010 +0200 +++ b/tests/test-push-http Wed Jun 30 18:15:23 2010 -0500 @@ -39,11 +39,9 @@ echo % expect success echo 'allow_push = *' >> .hg/hgrc echo '[hooks]' >> .hg/hgrc -echo 'changegroup = python ../printenv.py changegroup 0 ../urls' >> .hg/hgrc +echo 'changegroup = python ../printenv.py changegroup 0' >> .hg/hgrc req -cat ../urls - hg rollback echo % expect authorization error: all users denied echo '[web]' > .hg/hgrc diff -r 1c1126b1d919 -r c37f35d7f2f5 tests/test-push-http.out --- a/tests/test-push-http.out Wed Jun 23 13:44:07 2010 +0200 +++ b/tests/test-push-http.out Wed Jun 30 18:15:23 2010 -0500 @@ -23,8 +23,8 @@ remote: adding manifests remote: adding file changes remote: added 1 changesets with 1 changes to 1 files +remote: changegroup hook: HG_NODE=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_SOURCE=serve HG_URL=remote:http % serve errors -changegroup hook: HG_NODE=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_SOURCE=serve HG_URL=remote:http rolling back to revision 0 (undo serve) % expect authorization error: all users denied abort: authorization failed