##// END OF EJS Templates
protocol: clean up call-like functions in http and ssh clients
Matt Mackall -
r11589:e8d22fe2 default
parent child Browse files
Show More
@@ -54,7 +54,7 b' class httprepository(wireproto.wirerepos'
54 def get_caps(self):
54 def get_caps(self):
55 if self.caps is None:
55 if self.caps is None:
56 try:
56 try:
57 self.caps = set(self.do_read('capabilities').split())
57 self.caps = set(self._call('capabilities').split())
58 except error.RepoError:
58 except error.RepoError:
59 self.caps = set()
59 self.caps = set()
60 self.ui.debug('capabilities: %s\n' %
60 self.ui.debug('capabilities: %s\n' %
@@ -66,7 +66,7 b' class httprepository(wireproto.wirerepos'
66 def lock(self):
66 def lock(self):
67 raise util.Abort(_('operation not supported over http'))
67 raise util.Abort(_('operation not supported over http'))
68
68
69 def do_cmd(self, cmd, **args):
69 def _callstream(self, cmd, **args):
70 data = args.pop('data', None)
70 data = args.pop('data', None)
71 headers = args.pop('headers', {})
71 headers = args.pop('headers', {})
72 self.ui.debug("sending %s command\n" % cmd)
72 self.ui.debug("sending %s command\n" % cmd)
@@ -130,33 +130,27 b' class httprepository(wireproto.wirerepos'
130
130
131 return resp
131 return resp
132
132
133 def do_read(self, cmd, **args):
133 def _call(self, cmd, **args):
134 fp = self.do_cmd(cmd, **args)
134 fp = self._callstream(cmd, **args)
135 try:
135 try:
136 return fp.read()
136 return fp.read()
137 finally:
137 finally:
138 # if using keepalive, allow connection to be reused
138 # if using keepalive, allow connection to be reused
139 fp.close()
139 fp.close()
140
140
141 def _call(self, cmd, **args):
142 return self.do_read(cmd, **args)
143
144 def _callstream(self, cmd, **args):
145 return self.do_cmd(cmd, **args)
146
147 def _abort(self, exception):
141 def _abort(self, exception):
148 raise exception
142 raise exception
149
143
150 def changegroup(self, nodes, kind):
144 def changegroup(self, nodes, kind):
151 n = " ".join(map(hex, nodes))
145 n = " ".join(map(hex, nodes))
152 f = self.do_cmd("changegroup", roots=n)
146 f = self._callstream("changegroup", roots=n)
153 return util.chunkbuffer(zgenerator(f))
147 return util.chunkbuffer(zgenerator(f))
154
148
155 def changegroupsubset(self, bases, heads, source):
149 def changegroupsubset(self, bases, heads, source):
156 self.requirecap('changegroupsubset', _('look up remote changes'))
150 self.requirecap('changegroupsubset', _('look up remote changes'))
157 baselst = " ".join([hex(n) for n in bases])
151 baselst = " ".join([hex(n) for n in bases])
158 headlst = " ".join([hex(n) for n in heads])
152 headlst = " ".join([hex(n) for n in heads])
159 f = self.do_cmd("changegroupsubset", bases=baselst, heads=headlst)
153 f = self._callstream("changegroupsubset", bases=baselst, heads=headlst)
160 return util.chunkbuffer(zgenerator(f))
154 return util.chunkbuffer(zgenerator(f))
161
155
162 def unbundle(self, cg, heads, source):
156 def unbundle(self, cg, heads, source):
@@ -187,7 +181,7 b' class httprepository(wireproto.wirerepos'
187 fp = url.httpsendfile(tempname, "rb")
181 fp = url.httpsendfile(tempname, "rb")
188 try:
182 try:
189 try:
183 try:
190 resp = self.do_read(
184 resp = self._call(
191 'unbundle', data=fp,
185 'unbundle', data=fp,
192 headers={'Content-Type': 'application/mercurial-0.1'},
186 headers={'Content-Type': 'application/mercurial-0.1'},
193 heads=' '.join(map(hex, heads)))
187 heads=' '.join(map(hex, heads)))
@@ -65,8 +65,8 b' class sshrepository(wireproto.wirereposi'
65 self.pipeo, self.pipei, self.pipee = util.popen3(cmd)
65 self.pipeo, self.pipei, self.pipee = util.popen3(cmd)
66
66
67 # skip any noise generated by remote shell
67 # skip any noise generated by remote shell
68 self.do_cmd("hello")
68 self._callstream("hello")
69 r = self.do_cmd("between", pairs=("%s-%s" % ("0"*40, "0"*40)))
69 r = self._callstream("between", pairs=("%s-%s" % ("0"*40, "0"*40)))
70 lines = ["", "dummy"]
70 lines = ["", "dummy"]
71 max_noise = 500
71 max_noise = 500
72 while lines[-1] and max_noise:
72 while lines[-1] and max_noise:
@@ -118,7 +118,7 b' class sshrepository(wireproto.wirereposi'
118
118
119 __del__ = cleanup
119 __del__ = cleanup
120
120
121 def do_cmd(self, cmd, **args):
121 def _callstream(self, cmd, **args):
122 self.ui.debug("sending %s command\n" % cmd)
122 self.ui.debug("sending %s command\n" % cmd)
123 self.pipeo.write("%s\n" % cmd)
123 self.pipeo.write("%s\n" % cmd)
124 for k, v in sorted(args.iteritems()):
124 for k, v in sorted(args.iteritems()):
@@ -128,17 +128,10 b' class sshrepository(wireproto.wirereposi'
128
128
129 return self.pipei
129 return self.pipei
130
130
131 def call(self, cmd, **args):
131 def _call(self, cmd, **args):
132 self.do_cmd(cmd, **args)
132 self._callstream(cmd, **args)
133 return self._recv()
133 return self._recv()
134
134
135 def _call(self, cmd, **args):
136 self.do_cmd(cmd, **args)
137 return self._recv()
138
139 def _callstream(self, cmd, **args):
140 return self.do_cmd(cmd, **args)
141
142 def _recv(self):
135 def _recv(self):
143 l = self.pipei.readline()
136 l = self.pipei.readline()
144 self.readerr()
137 self.readerr()
@@ -157,28 +150,28 b' class sshrepository(wireproto.wirereposi'
157 self.readerr()
150 self.readerr()
158
151
159 def lock(self):
152 def lock(self):
160 self.call("lock")
153 self._call("lock")
161 return remotelock(self)
154 return remotelock(self)
162
155
163 def unlock(self):
156 def unlock(self):
164 self.call("unlock")
157 self._call("unlock")
165
158
166 def changegroup(self, nodes, kind):
159 def changegroup(self, nodes, kind):
167 n = " ".join(map(hex, nodes))
160 n = " ".join(map(hex, nodes))
168 return self.do_cmd("changegroup", roots=n)
161 return self._callstream("changegroup", roots=n)
169
162
170 def changegroupsubset(self, bases, heads, kind):
163 def changegroupsubset(self, bases, heads, kind):
171 self.requirecap('changegroupsubset', _('look up remote changes'))
164 self.requirecap('changegroupsubset', _('look up remote changes'))
172 bases = " ".join(map(hex, bases))
165 bases = " ".join(map(hex, bases))
173 heads = " ".join(map(hex, heads))
166 heads = " ".join(map(hex, heads))
174 return self.do_cmd("changegroupsubset", bases=bases, heads=heads)
167 return self._callstream("changegroupsubset", bases=bases, heads=heads)
175
168
176 def unbundle(self, cg, heads, source):
169 def unbundle(self, cg, heads, source):
177 '''Send cg (a readable file-like object representing the
170 '''Send cg (a readable file-like object representing the
178 changegroup to push, typically a chunkbuffer object) to the
171 changegroup to push, typically a chunkbuffer object) to the
179 remote server as a bundle. Return an integer indicating the
172 remote server as a bundle. Return an integer indicating the
180 result of the push (see localrepository.addchangegroup()).'''
173 result of the push (see localrepository.addchangegroup()).'''
181 d = self.call("unbundle", heads=' '.join(map(hex, heads)))
174 d = self._call("unbundle", heads=' '.join(map(hex, heads)))
182 if d:
175 if d:
183 # remote may send "unsynced changes"
176 # remote may send "unsynced changes"
184 self.abort(error.RepoError(_("push refused: %s") % d))
177 self.abort(error.RepoError(_("push refused: %s") % d))
@@ -206,7 +199,7 b' class sshrepository(wireproto.wirereposi'
206 '''Send a changegroup to the remote server. Return an integer
199 '''Send a changegroup to the remote server. Return an integer
207 similar to unbundle(). DEPRECATED, since it requires locking the
200 similar to unbundle(). DEPRECATED, since it requires locking the
208 remote.'''
201 remote.'''
209 d = self.call("addchangegroup")
202 d = self._call("addchangegroup")
210 if d:
203 if d:
211 self.abort(error.RepoError(_("push refused: %s") % d))
204 self.abort(error.RepoError(_("push refused: %s") % d))
212 while 1:
205 while 1:
General Comments 0
You need to be logged in to leave comments. Login now