Patchwork D317: wireproto: properly implement batchable checking

login
register
mail settings
Submitter phabricator
Date Aug. 10, 2017, 6:47 a.m.
Message ID <differential-rev-PHID-DREV-g36y76iyjqkqlselpjzx-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/22827/
State Superseded
Headers show

Comments

phabricator - Aug. 10, 2017, 6:47 a.m.
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D317

AFFECTED FILES
  mercurial/wireproto.py

CHANGE DETAILS




To: indygreg, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py
--- a/mercurial/wireproto.py
+++ b/mercurial/wireproto.py
@@ -120,9 +120,13 @@ 
         self._remote = remote
 
     def __getattr__(self, name):
-        if not getattr(self._remote, name, False):
-            raise AttributeError(
-                'Attempted to iterbatch non-batchable call to %r' % name)
+        # Validate this method is batchable, since submit() only supports
+        # batchable methods.
+        fn = getattr(self._remote, name)
+        if not getattr(fn, 'batchable', None):
+            raise error.ProgrammingError('Attempted to batch a non-batchable '
+                                         'call to %r' % name)
+
         return super(remoteiterbatcher, self).__getattr__(name)
 
     def submit(self):