wireproto: introduce pusherr() to deal with "unsynced changes" error
authorBenoit Boissinot <benoit.boissinot@ens-lyon.org>
Mon, 11 Oct 2010 12:45:36 -0500
changeset 12703 40bb5853fc4b
parent 12702 f747c085b789
child 12704 ca6e2adc3e4d
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
mercurial/hgweb/protocol.py
mercurial/sshserver.py
mercurial/wireproto.py
--- 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)