Mercurial > public > mercurial-scm > hg
comparison mercurial/wireproto.py @ 33764:297d1b70685c
wireproto: properly implement batchable checking
remoteiterbatcher (unlike remotebatcher) only supports batchable
commands. This claim can be validated by comparing their
implementations of submit() and noting how remoteiterbatcher assumes
the invoked method has a "batchable" attribute, which is set by
@peer.batchable.
remoteiterbatcher has a custom __getitem__ that was trying to
validate that only batchable methods are called. However, it was only
validating that the called method exists, not that it is batchable.
This wasn't a big deal since remoteiterbatcher.submit() would raise
an AttributeError attempting to `mtd.batchable(...)`.
Let's fix the check and convert it to ProgrammingError, which may
not have been around when this was originally implemented.
Differential Revision: https://phab.mercurial-scm.org/D317
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 09 Aug 2017 21:51:45 -0700 |
parents | 0407a51b9d8c |
children | e2fc2122029c |
comparison
equal
deleted
inserted
replaced
33763:dcdc17551653 | 33764:297d1b70685c |
---|---|
118 def __init__(self, remote): | 118 def __init__(self, remote): |
119 super(remoteiterbatcher, self).__init__() | 119 super(remoteiterbatcher, self).__init__() |
120 self._remote = remote | 120 self._remote = remote |
121 | 121 |
122 def __getattr__(self, name): | 122 def __getattr__(self, name): |
123 if not getattr(self._remote, name, False): | 123 # Validate this method is batchable, since submit() only supports |
124 raise AttributeError( | 124 # batchable methods. |
125 'Attempted to iterbatch non-batchable call to %r' % name) | 125 fn = getattr(self._remote, name) |
126 if not getattr(fn, 'batchable', None): | |
127 raise error.ProgrammingError('Attempted to batch a non-batchable ' | |
128 'call to %r' % name) | |
129 | |
126 return super(remoteiterbatcher, self).__getattr__(name) | 130 return super(remoteiterbatcher, self).__getattr__(name) |
127 | 131 |
128 def submit(self): | 132 def submit(self): |
129 """Break the batch request into many patch calls and pipeline them. | 133 """Break the batch request into many patch calls and pipeline them. |
130 | 134 |