changeset 17793:8474be4412ca

wireproto: fix pushkey hook failure and output on remote http repo Over http, a failed pushkey hook simply crashed the server, and successful hook output was never sent to the client.
author Wagner Bruna <wbruna@softwareexpress.com.br>
date Mon, 15 Oct 2012 18:37:34 -0300
parents a1c4b21fc1b2
children a03cca2cf6c2
files mercurial/wireproto.py tests/test-push-http.t
diffstat 2 files changed, 49 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/wireproto.py	Tue Oct 16 17:09:50 2012 -0500
+++ b/mercurial/wireproto.py	Mon Oct 15 18:37:34 2012 -0300
@@ -503,6 +503,20 @@
     else:
         new = encoding.tolocal(new) # normal path
 
+    if util.safehasattr(proto, 'restore'):
+
+        proto.redirect()
+
+        try:
+            r = repo.pushkey(encoding.tolocal(namespace), encoding.tolocal(key),
+                             encoding.tolocal(old), new) or False
+        except util.Abort:
+            r = False
+
+        output = proto.restore()
+
+        return '%s\n%s' % (int(r), output)
+
     r = repo.pushkey(encoding.tolocal(namespace), encoding.tolocal(key),
                      encoding.tolocal(old), new)
     return '%s\n' % int(r)
--- a/tests/test-push-http.t	Tue Oct 16 17:09:50 2012 -0500
+++ b/tests/test-push-http.t	Mon Oct 15 18:37:34 2012 -0300
@@ -59,6 +59,7 @@
   $ echo 'allow_push = *' >> .hg/hgrc
   $ echo '[hooks]' >> .hg/hgrc
   $ echo "changegroup = python \"$TESTDIR/printenv.py\" changegroup 0" >> .hg/hgrc
+  $ echo "pushkey = python \"$TESTDIR/printenv.py\" pushkey 0" >> .hg/hgrc
   $ req
   pushing to http://localhost:$HGPORT/
   searching for changes
@@ -67,6 +68,7 @@
   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:*: (glob)
+  remote: pushkey hook: HG_KEY=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_NAMESPACE=phases HG_NEW=0 HG_OLD=1 HG_RET=1
   % serve errors
   $ hg rollback
   repository tip rolled back to revision 0 (undo serve)
@@ -83,6 +85,7 @@
   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:*: (glob)
+  remote: pushkey hook: HG_KEY=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_NAMESPACE=phases HG_NEW=0 HG_OLD=1 HG_RET=1
   % serve errors
   $ hg rollback
   repository tip rolled back to revision 0 (undo serve)
@@ -99,10 +102,42 @@
   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:*: (glob)
+  remote: pushkey hook: HG_KEY=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_NAMESPACE=phases HG_NEW=0 HG_OLD=1 HG_RET=1
   % serve errors
   $ hg rollback
   repository tip rolled back to revision 0 (undo serve)
 
+expect push success, phase change failure
+
+  $ echo '[web]' > .hg/hgrc
+  $ echo 'push_ssl = false' >> .hg/hgrc
+  $ echo 'allow_push = *' >> .hg/hgrc
+  $ echo '[hooks]' >> .hg/hgrc
+  $ echo 'prepushkey = python "$TESTDIR/printenv.py" prepushkey 1' >> .hg/hgrc
+  $ req
+  pushing to http://localhost:$HGPORT/
+  searching for changes
+  remote: adding changesets
+  remote: adding manifests
+  remote: adding file changes
+  remote: added 1 changesets with 1 changes to 1 files
+  remote: prepushkey hook: HG_KEY=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_NAMESPACE=phases HG_NEW=0 HG_OLD=1
+  updating ba677d0156c1 to public failed!
+  % serve errors
+
+expect phase change success
+
+  $ echo 'prepushkey = python "$TESTDIR/printenv.py" prepushkey 0' >> .hg/hgrc
+  $ req
+  pushing to http://localhost:$HGPORT/
+  searching for changes
+  no changes found
+  remote: prepushkey hook: HG_KEY=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_NAMESPACE=phases HG_NEW=0 HG_OLD=1
+  % serve errors
+  [1]
+  $ hg rollback
+  repository tip rolled back to revision 0 (undo serve)
+
 expect authorization error: all users denied
 
   $ echo '[web]' > .hg/hgrc