diff mercurial/sshrepo.py @ 11592:26e0782b8380

protocol: unify client unbundle support - introduce _callpush helper - factor out differences in result handling into helpers - unify
author Matt Mackall <mpm@selenic.com>
date Wed, 14 Jul 2010 17:12:18 -0500
parents 0d9cb3f3b0a1
children 47ca289a3a08
line wrap: on
line diff
--- a/mercurial/sshrepo.py	Wed Jul 14 17:09:31 2010 -0500
+++ b/mercurial/sshrepo.py	Wed Jul 14 17:12:18 2010 -0500
@@ -128,6 +128,21 @@
         self._callstream(cmd, **args)
         return self._recv()
 
+    def _callpush(self, cmd, fp, **args):
+        r = self._call(cmd, **args)
+        if r:
+            return '', r
+        while 1:
+            d = fp.read(4096)
+            if not d:
+                break
+            self._send(d)
+        self._send("", flush=True)
+        r = self._recv()
+        if r:
+            return '', r
+        return self._recv(), ''
+
     def _decompress(self, stream):
         return stream
 
@@ -155,35 +170,6 @@
     def unlock(self):
         self._call("unlock")
 
-    def unbundle(self, cg, heads, source):
-        '''Send cg (a readable file-like object representing the
-        changegroup to push, typically a chunkbuffer object) to the
-        remote server as a bundle. Return an integer indicating the
-        result of the push (see localrepository.addchangegroup()).'''
-        d = self._call("unbundle", heads=' '.join(map(hex, heads)))
-        if d:
-            # remote may send "unsynced changes"
-            self._abort(error.RepoError(_("push refused: %s") % d))
-
-        while 1:
-            d = cg.read(4096)
-            if not d:
-                break
-            self._send(d)
-
-        self._send("", flush=True)
-
-        r = self._recv()
-        if r:
-            # remote may send "unsynced changes"
-            self._abort(error.RepoError(_("push failed: %s") % r))
-
-        r = self._recv()
-        try:
-            return int(r)
-        except:
-            self._abort(error.ResponseError(_("unexpected response:"), r))
-
     def addchangegroup(self, cg, source, url):
         '''Send a changegroup to the remote server.  Return an integer
         similar to unbundle(). DEPRECATED, since it requires locking the