changeset 12703:40bb5853fc4b

wireproto: introduce pusherr() to deal with "unsynced changes" error The behaviour between http and ssh still differ: - the "unsynced changes" is seen as a remote output in the http cases - but it is correctly seen as a push error for ssh
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Mon, 11 Oct 2010 12:45:36 -0500
parents f747c085b789
children ca6e2adc3e4d
files mercurial/hgweb/protocol.py mercurial/sshserver.py mercurial/wireproto.py
diffstat 3 files changed, 15 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/protocol.py	Mon Oct 11 12:44:33 2010 -0500
+++ b/mercurial/hgweb/protocol.py	Mon Oct 11 12:45:36 2010 -0500
@@ -66,3 +66,8 @@
         sys.stdout, sys.stderr = p.oldio
         req.respond(HTTP_OK, HGTYPE)
         return ['%d\n%s' % (rsp.res, val)]
+    elif isinstance(rsp, wireproto.pusherr):
+        sys.stdout, sys.stderr = p.oldio
+        rsp = '0\n%s\n' % rsp.res
+        req.respond(HTTP_OK, HGTYPE, length=len(rsp))
+        return [rsp]
--- a/mercurial/sshserver.py	Mon Oct 11 12:44:33 2010 -0500
+++ b/mercurial/sshserver.py	Mon Oct 11 12:45:36 2010 -0500
@@ -79,6 +79,9 @@
         self.sendresponse('')
         self.sendresponse(str(rsp.res))
 
+    def sendpusherror(self, rsp):
+        self.sendresponse(rsp.res)
+
     def serve_forever(self):
         try:
             while self.serve_one():
@@ -92,6 +95,7 @@
         str: sendresponse,
         wireproto.streamres: sendstream,
         wireproto.pushres: sendpushresponse,
+        wireproto.pusherr: sendpusherror,
     }
 
     def serve_one(self):
--- a/mercurial/wireproto.py	Mon Oct 11 12:44:33 2010 -0500
+++ b/mercurial/wireproto.py	Mon Oct 11 12:45:36 2010 -0500
@@ -142,6 +142,10 @@
     def __init__(self, res):
         self.res = res
 
+class pusherr(object):
+    def __init__(self, res):
+        self.res = res
+
 def dispatch(repo, proto, command):
     func, spec = commands[command]
     args = proto.getargs(spec)
@@ -285,7 +289,7 @@
 
     # fail early if possible
     if not check_heads():
-        return 'unsynced changes'
+        return pusherr('unsynced changes')
 
     # write bundle data to temporary file because it can be big
     fd, tempname = tempfile.mkstemp(prefix='hg-unbundle-')
@@ -298,7 +302,7 @@
             if not check_heads():
                 # someone else committed/pushed/unbundled while we
                 # were transferring data
-                return 'unsynced changes'
+                return pusherr('unsynced changes')
 
             # push can proceed
             fp.seek(0)