Mercurial > hg
comparison mercurial/wireproto.py @ 33767:b47fe9733d76
peer: remove non iterating batcher (API)
The last use of this API was removed in b6e71f8af5b8 in 2016. While
not formally deprecated, as of the last commit the code is no longer
explicitly tested. I think the new API has existed long enough for
people to transition to it.
I also have plans to more formalize the peer API and removing batch()
makes that work easier.
I'm not convinced the current client-side API around batching is
great. But it's the best we have at the moment.
.. api:: remove peer.batch()
Replace with peer.iterbatch().
Differential Revision: https://phab.mercurial-scm.org/D320
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 09 Aug 2017 23:35:20 -0700 |
parents | 4c706037adef |
children | dedab036215d |
comparison
equal
deleted
inserted
replaced
33766:4c706037adef | 33767:b47fe9733d76 |
---|---|
6 # GNU General Public License version 2 or any later version. | 6 # GNU General Public License version 2 or any later version. |
7 | 7 |
8 from __future__ import absolute_import | 8 from __future__ import absolute_import |
9 | 9 |
10 import hashlib | 10 import hashlib |
11 import itertools | |
12 import os | 11 import os |
13 import tempfile | 12 import tempfile |
14 | 13 |
15 from .i18n import _ | 14 from .i18n import _ |
16 from .node import ( | 15 from .node import ( |
77 # | 76 # |
78 #def restore(self): | 77 #def restore(self): |
79 # """reinstall previous stdout and stderr and return intercepted stdout | 78 # """reinstall previous stdout and stderr and return intercepted stdout |
80 # """ | 79 # """ |
81 # raise NotImplementedError() | 80 # raise NotImplementedError() |
82 | |
83 class remotebatch(peer.batcher): | |
84 '''batches the queued calls; uses as few roundtrips as possible''' | |
85 def __init__(self, remote): | |
86 '''remote must support _submitbatch(encbatch) and | |
87 _submitone(op, encargs)''' | |
88 peer.batcher.__init__(self) | |
89 self.remote = remote | |
90 def submit(self): | |
91 req, rsp = [], [] | |
92 for name, args, opts, resref in self.calls: | |
93 mtd = getattr(self.remote, name) | |
94 batchablefn = getattr(mtd, 'batchable', None) | |
95 if batchablefn is not None: | |
96 batchable = batchablefn(mtd.im_self, *args, **opts) | |
97 encargsorres, encresref = next(batchable) | |
98 assert encresref | |
99 req.append((name, encargsorres,)) | |
100 rsp.append((batchable, encresref, resref,)) | |
101 else: | |
102 if req: | |
103 self._submitreq(req, rsp) | |
104 req, rsp = [], [] | |
105 resref.set(mtd(*args, **opts)) | |
106 if req: | |
107 self._submitreq(req, rsp) | |
108 def _submitreq(self, req, rsp): | |
109 encresults = self.remote._submitbatch(req) | |
110 for encres, r in zip(encresults, rsp): | |
111 batchable, encresref, resref = r | |
112 encresref.set(encres) | |
113 resref.set(next(batchable)) | |
114 | 81 |
115 class remoteiterbatcher(peer.iterbatcher): | 82 class remoteiterbatcher(peer.iterbatcher): |
116 def __init__(self, remote): | 83 def __init__(self, remote): |
117 super(remoteiterbatcher, self).__init__() | 84 super(remoteiterbatcher, self).__init__() |
118 self._remote = remote | 85 self._remote = remote |
251 Methods commonly call wire protocol commands of the same name. | 218 Methods commonly call wire protocol commands of the same name. |
252 | 219 |
253 See also httppeer.py and sshpeer.py for protocol-specific | 220 See also httppeer.py and sshpeer.py for protocol-specific |
254 implementations of this interface. | 221 implementations of this interface. |
255 """ | 222 """ |
256 def batch(self): | |
257 if self.capable('batch'): | |
258 return remotebatch(self) | |
259 else: | |
260 return peer.localbatch(self) | |
261 def _submitbatch(self, req): | 223 def _submitbatch(self, req): |
262 """run batch request <req> on the server | 224 """run batch request <req> on the server |
263 | 225 |
264 Returns an iterator of the raw responses from the server. | 226 Returns an iterator of the raw responses from the server. |
265 """ | 227 """ |