Mercurial > hg
changeset 11469:c37f35d7f2f5 stable
http: deliver hook output to client
author | Maxim Khitrov <mkhitrov@gmail.com> |
---|---|
date | Wed, 30 Jun 2010 18:15:23 -0500 |
parents | 1c1126b1d919 |
children | 34e33d50c26b cc4e2a7ca23f |
files | mercurial/hook.py mercurial/util.py tests/test-push-http tests/test-push-http.out |
diffstat | 4 files changed, 22 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- 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:
--- 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:
--- 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
--- 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