changeset 11589:e8d22fe2ddab

protocol: clean up call-like functions in http and ssh clients
author Matt Mackall <mpm@selenic.com>
date Wed, 14 Jul 2010 17:07:10 -0500
parents 8a1f625e971d
children 0b15aee0a306
files mercurial/httprepo.py mercurial/sshrepo.py
diffstat 2 files changed, 18 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/httprepo.py	Wed Jul 14 16:55:44 2010 -0500
+++ b/mercurial/httprepo.py	Wed Jul 14 17:07:10 2010 -0500
@@ -54,7 +54,7 @@
     def get_caps(self):
         if self.caps is None:
             try:
-                self.caps = set(self.do_read('capabilities').split())
+                self.caps = set(self._call('capabilities').split())
             except error.RepoError:
                 self.caps = set()
             self.ui.debug('capabilities: %s\n' %
@@ -66,7 +66,7 @@
     def lock(self):
         raise util.Abort(_('operation not supported over http'))
 
-    def do_cmd(self, cmd, **args):
+    def _callstream(self, cmd, **args):
         data = args.pop('data', None)
         headers = args.pop('headers', {})
         self.ui.debug("sending %s command\n" % cmd)
@@ -130,33 +130,27 @@
 
         return resp
 
-    def do_read(self, cmd, **args):
-        fp = self.do_cmd(cmd, **args)
+    def _call(self, cmd, **args):
+        fp = self._callstream(cmd, **args)
         try:
             return fp.read()
         finally:
             # if using keepalive, allow connection to be reused
             fp.close()
 
-    def _call(self, cmd, **args):
-        return self.do_read(cmd, **args)
-
-    def _callstream(self, cmd, **args):
-        return self.do_cmd(cmd, **args)
-
     def _abort(self, exception):
         raise exception
 
     def changegroup(self, nodes, kind):
         n = " ".join(map(hex, nodes))
-        f = self.do_cmd("changegroup", roots=n)
+        f = self._callstream("changegroup", roots=n)
         return util.chunkbuffer(zgenerator(f))
 
     def changegroupsubset(self, bases, heads, source):
         self.requirecap('changegroupsubset', _('look up remote changes'))
         baselst = " ".join([hex(n) for n in bases])
         headlst = " ".join([hex(n) for n in heads])
-        f = self.do_cmd("changegroupsubset", bases=baselst, heads=headlst)
+        f = self._callstream("changegroupsubset", bases=baselst, heads=headlst)
         return util.chunkbuffer(zgenerator(f))
 
     def unbundle(self, cg, heads, source):
@@ -187,7 +181,7 @@
         fp = url.httpsendfile(tempname, "rb")
         try:
             try:
-                resp = self.do_read(
+                resp = self._call(
                      'unbundle', data=fp,
                      headers={'Content-Type': 'application/mercurial-0.1'},
                      heads=' '.join(map(hex, heads)))
--- a/mercurial/sshrepo.py	Wed Jul 14 16:55:44 2010 -0500
+++ b/mercurial/sshrepo.py	Wed Jul 14 17:07:10 2010 -0500
@@ -65,8 +65,8 @@
         self.pipeo, self.pipei, self.pipee = util.popen3(cmd)
 
         # skip any noise generated by remote shell
-        self.do_cmd("hello")
-        r = self.do_cmd("between", pairs=("%s-%s" % ("0"*40, "0"*40)))
+        self._callstream("hello")
+        r = self._callstream("between", pairs=("%s-%s" % ("0"*40, "0"*40)))
         lines = ["", "dummy"]
         max_noise = 500
         while lines[-1] and max_noise:
@@ -118,7 +118,7 @@
 
     __del__ = cleanup
 
-    def do_cmd(self, cmd, **args):
+    def _callstream(self, cmd, **args):
         self.ui.debug("sending %s command\n" % cmd)
         self.pipeo.write("%s\n" % cmd)
         for k, v in sorted(args.iteritems()):
@@ -128,17 +128,10 @@
 
         return self.pipei
 
-    def call(self, cmd, **args):
-        self.do_cmd(cmd, **args)
+    def _call(self, cmd, **args):
+        self._callstream(cmd, **args)
         return self._recv()
 
-    def _call(self, cmd, **args):
-        self.do_cmd(cmd, **args)
-        return self._recv()
-
-    def _callstream(self, cmd, **args):
-        return self.do_cmd(cmd, **args)
-
     def _recv(self):
         l = self.pipei.readline()
         self.readerr()
@@ -157,28 +150,28 @@
         self.readerr()
 
     def lock(self):
-        self.call("lock")
+        self._call("lock")
         return remotelock(self)
 
     def unlock(self):
-        self.call("unlock")
+        self._call("unlock")
 
     def changegroup(self, nodes, kind):
         n = " ".join(map(hex, nodes))
-        return self.do_cmd("changegroup", roots=n)
+        return self._callstream("changegroup", roots=n)
 
     def changegroupsubset(self, bases, heads, kind):
         self.requirecap('changegroupsubset', _('look up remote changes'))
         bases = " ".join(map(hex, bases))
         heads = " ".join(map(hex, heads))
-        return self.do_cmd("changegroupsubset", bases=bases, heads=heads)
+        return self._callstream("changegroupsubset", bases=bases, heads=heads)
 
     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)))
+        d = self._call("unbundle", heads=' '.join(map(hex, heads)))
         if d:
             # remote may send "unsynced changes"
             self.abort(error.RepoError(_("push refused: %s") % d))
@@ -206,7 +199,7 @@
         '''Send a changegroup to the remote server.  Return an integer
         similar to unbundle(). DEPRECATED, since it requires locking the
         remote.'''
-        d = self.call("addchangegroup")
+        d = self._call("addchangegroup")
         if d:
             self.abort(error.RepoError(_("push refused: %s") % d))
         while 1: