legacy-push: fix the code forbidding legacy obsmarkers pulling
authorPierre-Yves David <pierre-yves.david@octobus.net>
Fri, 23 Feb 2018 11:02:59 +0100
changeset 3505 25155eb05f5f
parent 3504 5dc34b857114
child 3506 6b4272bbb65d
legacy-push: fix the code forbidding legacy obsmarkers pulling changeset e69e65b2b4a9 in code remove a key try/except. We reintroduce it for compatibility.
hgext3rd/evolve/obsexchange.py
tests/test-wireproto.t
--- a/hgext3rd/evolve/obsexchange.py	Wed Feb 21 17:45:50 2018 +0100
+++ b/hgext3rd/evolve/obsexchange.py	Fri Feb 23 11:02:59 2018 +0100
@@ -25,6 +25,7 @@
     pushkey,
     util,
     wireproto,
+    wireprotoserver,
 )
 
 from mercurial.hgweb import common as hgwebcommon
@@ -230,6 +231,26 @@
         raise err
     return {}
 
+# reinstall dispatch catching ResponseError as in hg 4.5 <
+@eh.wrapfunction(wireprotoserver, 'parsehttprequest')
+def parsehttprequest(orig, repo, req, query):
+    protohandler = orig(repo, req, query)
+    olddispatch = protohandler['dispatch']
+
+    def newdispatch():
+        try:
+            return olddispatch()
+        except hgwebcommon.ErrorResponse as inst:
+            if protohandler['cmd'] != 'listkeys':
+                raise
+            req.headers.append((r'Connection', r'Close'))
+            req.respond(inst, wireprotoserver.HGTYPE,
+                        body='0\n%s\n' % inst)
+            return ''
+
+    protohandler['dispatch'] = newdispatch
+    return protohandler
+
 @eh.uisetup
 def setuppushkeyforbidding(ui):
     pushkey._namespaces['obsolete'] = (forbidpushkey, forbidlistkey)
--- a/tests/test-wireproto.t	Wed Feb 21 17:45:50 2018 +0100
+++ b/tests/test-wireproto.t	Fri Feb 23 11:02:59 2018 +0100
@@ -202,6 +202,7 @@
   $ hg debugpushkey http://localhost:$HGPORT/ obsolete
   abort: HTTP Error 410: won't exchange obsmarkers through pushkey
   [255]
+  $ cat errors.log
   $ hg debugpushkey ssh://user@dummy/server obsolete
   remote: abort: won't exchange obsmarkers through pushkey
   remote: (upgrade your client or server to use the bundle2 protocol)