113 self.pipeo.flush() |
113 self.pipeo.flush() |
114 |
114 |
115 return self.pipei |
115 return self.pipei |
116 |
116 |
117 def call(self, cmd, **args): |
117 def call(self, cmd, **args): |
118 r = self.do_cmd(cmd, **args) |
118 self.do_cmd(cmd, **args) |
119 l = r.readline() |
119 return self._recv() |
|
120 |
|
121 def _recv(self): |
|
122 l = self.pipei.readline() |
120 self.readerr() |
123 self.readerr() |
121 try: |
124 try: |
122 l = int(l) |
125 l = int(l) |
123 except: |
126 except: |
124 self.raise_(util.UnexpectedOutput(_("unexpected response:"), l)) |
127 self.raise_(util.UnexpectedOutput(_("unexpected response:"), l)) |
125 return r.read(l) |
128 return self.pipei.read(l) |
|
129 |
|
130 def _send(self, data, flush=False): |
|
131 self.pipeo.write("%d\n" % len(data)) |
|
132 if data: |
|
133 self.pipeo.write(data) |
|
134 if flush: |
|
135 self.pipeo.flush() |
|
136 self.readerr() |
126 |
137 |
127 def lock(self): |
138 def lock(self): |
128 self.call("lock") |
139 self.call("lock") |
129 return remotelock(self) |
140 return remotelock(self) |
130 |
141 |
181 # remote may send "unsynced changes" |
192 # remote may send "unsynced changes" |
182 self.raise_(repo.RepoError(_("push refused: %s") % d)) |
193 self.raise_(repo.RepoError(_("push refused: %s") % d)) |
183 |
194 |
184 while 1: |
195 while 1: |
185 d = cg.read(4096) |
196 d = cg.read(4096) |
186 if not d: break |
197 if not d: |
187 self.pipeo.write(str(len(d)) + '\n') |
198 break |
188 self.pipeo.write(d) |
199 self._send(d) |
189 self.readerr() |
200 |
190 |
201 self._send("", flush=True) |
191 self.pipeo.write('0\n') |
202 |
192 self.pipeo.flush() |
203 r = self._recv() |
193 |
|
194 self.readerr() |
|
195 l = int(self.pipei.readline()) |
|
196 r = self.pipei.read(l) |
|
197 if r: |
204 if r: |
198 # remote may send "unsynced changes" |
205 # remote may send "unsynced changes" |
199 self.raise_(hg.RepoError(_("push failed: %s") % r)) |
206 self.raise_(hg.RepoError(_("push failed: %s") % r)) |
200 |
207 |
201 self.readerr() |
208 r = self._recv() |
202 l = int(self.pipei.readline()) |
209 try: |
203 r = self.pipei.read(l) |
210 return int(r) |
204 return int(r) |
211 except: |
|
212 self.raise_(util.UnexpectedOutput(_("unexpected response:"), r)) |
205 |
213 |
206 def addchangegroup(self, cg, source, url): |
214 def addchangegroup(self, cg, source, url): |
207 d = self.call("addchangegroup") |
215 d = self.call("addchangegroup") |
208 if d: |
216 if d: |
209 self.raise_(repo.RepoError(_("push refused: %s") % d)) |
217 self.raise_(repo.RepoError(_("push refused: %s") % d)) |
210 while 1: |
218 while 1: |
211 d = cg.read(4096) |
219 d = cg.read(4096) |
212 if not d: break |
220 if not d: |
|
221 break |
213 self.pipeo.write(d) |
222 self.pipeo.write(d) |
214 self.readerr() |
223 self.readerr() |
215 |
224 |
216 self.pipeo.flush() |
225 self.pipeo.flush() |
217 |
226 |
218 self.readerr() |
227 self.readerr() |
219 l = int(self.pipei.readline()) |
228 r = self._recv() |
220 r = self.pipei.read(l) |
|
221 if not r: |
229 if not r: |
222 return 1 |
230 return 1 |
223 return int(r) |
231 try: |
|
232 return int(r) |
|
233 except: |
|
234 self.raise_(util.UnexpectedOutput(_("unexpected response:"), r)) |
224 |
235 |
225 def stream_out(self): |
236 def stream_out(self): |
226 return self.do_cmd('stream_out') |
237 return self.do_cmd('stream_out') |
227 |
238 |
228 instance = sshrepository |
239 instance = sshrepository |