hg: use command executor for wire protocol commands
authorGregory Szorc <gregory.szorc@gmail.com>
Fri, 13 Apr 2018 11:17:45 -0700
changeset 37640 ce8828217369
parent 37639 0e50dda7e9c1
child 37641 add129811176
hg: use command executor for wire protocol commands As part of this, I realized that some uses of lookup in a loop could be converted to use a batch request. But I didn't change behavior and left in a todo to track potentially changing this. Differential Revision: https://phab.mercurial-scm.org/D3291
mercurial/hg.py
--- a/mercurial/hg.py	Fri Apr 13 11:14:54 2018 -0700
+++ b/mercurial/hg.py	Fri Apr 13 11:17:45 2018 -0700
@@ -81,7 +81,9 @@
             raise error.Abort(_("remote branch lookup not supported"))
         revs.append(hashbranch)
         return revs, revs[0]
-    branchmap = peer.branchmap()
+
+    with peer.commandexecutor() as e:
+        branchmap = e.callcommand('branchmap', {}).result()
 
     def primary(branch):
         if branch == '.':
@@ -421,7 +423,15 @@
             raise error.Abort(_("src repository does not support "
                                "revision lookup and so doesn't "
                                "support clone by revision"))
-        revs = [srcpeer.lookup(r) for r in rev]
+
+        # TODO this is batchable.
+        remoterevs = []
+        for r in rev:
+            with srcpeer.commandexecutor() as e:
+                remoterevs.append(e.callcommand('lookup', {
+                    'key': r,
+                }).result())
+        revs = remoterevs
 
     # Obtain a lock before checking for or cloning the pooled repo otherwise
     # 2 clients may race creating or populating it.
@@ -567,7 +577,11 @@
             # raises RepoLookupError if revision 0 is filtered or otherwise
             # not available. If we fail to resolve, sharing is not enabled.
             try:
-                rootnode = srcpeer.lookup('0')
+                with srcpeer.commandexecutor() as e:
+                    rootnode = e.callcommand('lookup', {
+                        'key': '0',
+                    }).result()
+
                 if rootnode != node.nullid:
                     sharepath = os.path.join(sharepool, node.hex(rootnode))
                 else:
@@ -663,7 +677,16 @@
                     raise error.Abort(_("src repository does not support "
                                        "revision lookup and so doesn't "
                                        "support clone by revision"))
-                revs = [srcpeer.lookup(r) for r in revs]
+
+                # TODO this is batchable.
+                remoterevs = []
+                for rev in revs:
+                    with srcpeer.commandexecutor() as e:
+                        remoterevs.append(e.callcommand('lookup', {
+                            'key': rev,
+                        }).result())
+                revs = remoterevs
+
                 checkout = revs[0]
             else:
                 revs = None
@@ -705,7 +728,11 @@
 
             if update:
                 if update is not True:
-                    checkout = srcpeer.lookup(update)
+                    with srcpeer.commandexecutor() as e:
+                        checkout = e.callcommand('lookup', {
+                            'key': update,
+                        }).result()
+
                 uprev = None
                 status = None
                 if checkout is not None: