Mercurial > hg
comparison mercurial/wireproto.py @ 20905:167047ba3cfa
wireproto: drop the _decompress method in favor a new call type
We already have multiple call function for multiple return type. The
`_decompress` function is only used for http and seems like a layer violation.
We drop it in favor of a new call type dedicated to "stream that may be useful to
compress".
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Fri, 28 Mar 2014 14:24:13 -0700 |
parents | 3dbe6bcd7f62 |
children | 7a634b34fc91 |
comparison
equal
deleted
inserted
replaced
20904:3dbe6bcd7f62 | 20905:167047ba3cfa |
---|---|
312 def stream_out(self): | 312 def stream_out(self): |
313 return self._callstream('stream_out') | 313 return self._callstream('stream_out') |
314 | 314 |
315 def changegroup(self, nodes, kind): | 315 def changegroup(self, nodes, kind): |
316 n = encodelist(nodes) | 316 n = encodelist(nodes) |
317 f = self._callstream("changegroup", roots=n) | 317 f = self._callcompressable("changegroup", roots=n) |
318 return changegroupmod.unbundle10(self._decompress(f), 'UN') | 318 return changegroupmod.unbundle10(f, 'UN') |
319 | 319 |
320 def changegroupsubset(self, bases, heads, kind): | 320 def changegroupsubset(self, bases, heads, kind): |
321 self.requirecap('changegroupsubset', _('look up remote changes')) | 321 self.requirecap('changegroupsubset', _('look up remote changes')) |
322 bases = encodelist(bases) | 322 bases = encodelist(bases) |
323 heads = encodelist(heads) | 323 heads = encodelist(heads) |
324 f = self._callstream("changegroupsubset", | 324 f = self._callcompressable("changegroupsubset", |
325 bases=bases, heads=heads) | 325 bases=bases, heads=heads) |
326 return changegroupmod.unbundle10(self._decompress(f), 'UN') | 326 return changegroupmod.unbundle10(f, 'UN') |
327 | 327 |
328 def getbundle(self, source, heads=None, common=None, bundlecaps=None): | 328 def getbundle(self, source, heads=None, common=None, bundlecaps=None): |
329 self.requirecap('getbundle', _('look up remote changes')) | 329 self.requirecap('getbundle', _('look up remote changes')) |
330 opts = {} | 330 opts = {} |
331 if heads is not None: | 331 if heads is not None: |
332 opts['heads'] = encodelist(heads) | 332 opts['heads'] = encodelist(heads) |
333 if common is not None: | 333 if common is not None: |
334 opts['common'] = encodelist(common) | 334 opts['common'] = encodelist(common) |
335 if bundlecaps is not None: | 335 if bundlecaps is not None: |
336 opts['bundlecaps'] = ','.join(bundlecaps) | 336 opts['bundlecaps'] = ','.join(bundlecaps) |
337 f = self._callstream("getbundle", **opts) | 337 f = self._callcompressable("getbundle", **opts) |
338 return changegroupmod.unbundle10(self._decompress(f), 'UN') | 338 return changegroupmod.unbundle10(f, 'UN') |
339 | 339 |
340 def unbundle(self, cg, heads, source): | 340 def unbundle(self, cg, heads, source): |
341 '''Send cg (a readable file-like object representing the | 341 '''Send cg (a readable file-like object representing the |
342 changegroup to push, typically a chunkbuffer object) to the | 342 changegroup to push, typically a chunkbuffer object) to the |
343 remote server as a bundle. Return an integer indicating the | 343 remote server as a bundle. Return an integer indicating the |
386 The command is expected to return a stream. | 386 The command is expected to return a stream. |
387 | 387 |
388 returns the server reply as a file like object.""" | 388 returns the server reply as a file like object.""" |
389 raise NotImplementedError() | 389 raise NotImplementedError() |
390 | 390 |
391 def _callcompressable(self, cmd, **args): | |
392 """execute <cmd> on the server | |
393 | |
394 The command is expected to return a stream. | |
395 | |
396 The stream may have been compressed in some implementaitons. This | |
397 function takes care of the decompression. This is the only difference | |
398 with _callstream. | |
399 | |
400 returns the server reply as a file like object. | |
401 """ | |
402 raise NotImplementedError() | |
403 | |
391 def _callpush(self, cmd, fp, **args): | 404 def _callpush(self, cmd, fp, **args): |
392 """execute a <cmd> on server | 405 """execute a <cmd> on server |
393 | 406 |
394 The command is expected to be related to a push. Push has a special | 407 The command is expected to be related to a push. Push has a special |
395 return method. | 408 return method. |
399 """ | 412 """ |
400 raise NotImplementedError() | 413 raise NotImplementedError() |
401 | 414 |
402 def _abort(self, exception): | 415 def _abort(self, exception): |
403 """clearly abort the wire protocol connection and raise the exception | 416 """clearly abort the wire protocol connection and raise the exception |
404 """ | |
405 raise NotImplementedError() | |
406 | |
407 | |
408 def _decompress(self, stream): | |
409 """decompress a received stream | |
410 """ | 417 """ |
411 raise NotImplementedError() | 418 raise NotImplementedError() |
412 | 419 |
413 # server side | 420 # server side |
414 | 421 |