mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 23:38:50 +03:00
protocol: clean up call-like functions in http and ssh clients
This commit is contained in:
parent
60b140435c
commit
a91ad01089
@ -54,7 +54,7 @@ class httprepository(wireproto.wirerepository):
|
||||
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 @@ class httprepository(wireproto.wirerepository):
|
||||
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 @@ class httprepository(wireproto.wirerepository):
|
||||
|
||||
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 @@ class httprepository(wireproto.wirerepository):
|
||||
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)))
|
||||
|
@ -65,8 +65,8 @@ class sshrepository(wireproto.wirerepository):
|
||||
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 @@ class sshrepository(wireproto.wirerepository):
|
||||
|
||||
__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 @@ class sshrepository(wireproto.wirerepository):
|
||||
|
||||
return self.pipei
|
||||
|
||||
def call(self, cmd, **args):
|
||||
self.do_cmd(cmd, **args)
|
||||
return self._recv()
|
||||
|
||||
def _call(self, cmd, **args):
|
||||
self.do_cmd(cmd, **args)
|
||||
self._callstream(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 @@ class sshrepository(wireproto.wirerepository):
|
||||
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 @@ class sshrepository(wireproto.wirerepository):
|
||||
'''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:
|
||||
|
Loading…
Reference in New Issue
Block a user