[PATCH default] wireproto: fix pushkey hook failure and output on remote http repo
Wagner Bruna
wagner.bruna+mercurial at gmail.com
Tue Oct 16 14:45:46 CDT 2012
# HG changeset patch
# User Wagner Bruna <wbruna at softwareexpress.com.br>
# Date 1350337054 10800
# Node ID 211bcb29d36fabee31b7e8e130a52125d8aadf37
# Parent 823a7d79ef82010f614a2914f5f24723b2f815e1
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.
diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py
--- a/mercurial/wireproto.py
+++ b/mercurial/wireproto.py
@@ -503,6 +503,20 @@ def pushkey(repo, proto, namespace, key,
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)
diff --git a/tests/test-push-http.t b/tests/test-push-http.t
--- a/tests/test-push-http.t
+++ b/tests/test-push-http.t
@@ -59,6 +59,7 @@ expect success
$ 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 @@ expect success
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 @@ expect success, server lacks the httphea
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 @@ expect success, server lacks the unbundl
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
More information about the Mercurial-devel
mailing list