[PATCH RFC] discovery: batch heads and known into one request

Peter Arrenbrecht peter.arrenbrecht at gmail.com
Mon Mar 14 04:07:38 CDT 2011


# HG changeset patch
# User Peter Arrenbrecht <peter.arrenbrecht at gmail.com>
# Date 1300093205 -3600
discovery: batch heads and known into one request

diff --git a/mercurial/discovery.py b/mercurial/discovery.py
--- a/mercurial/discovery.py
+++ b/mercurial/discovery.py
@@ -24,8 +24,16 @@
     seenbranch = set()
     base = set()
 
+    known = None
     if not heads:
-        heads = remote.heads()
+        if commononly and remote.capable('batch'):
+            myheads = repo.heads()
+            req = [('heads', {},), ('known', {'nodes': myheads},)]
+            rsp = remote.batch(req)
+            _cmd, heads = rsp[0]
+            _cmd, known = rsp[1]
+        else:
+            heads = remote.heads()
 
     if repo.changelog.tip() == nullid:
         base.add(nullid)
@@ -38,8 +46,9 @@
     repo.ui.status(_("searching for changes\n"))
 
     if commononly:
-        myheads = repo.heads()
-        known = remote.known(myheads)
+        if known is None:
+            myheads = repo.heads()
+            known = remote.known(myheads)
         if util.all(known):
             hasincoming = set(heads).difference(set(myheads)) and True
             return myheads, hasincoming, heads
diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py
--- a/mercurial/wireproto.py
+++ b/mercurial/wireproto.py
@@ -50,6 +50,10 @@
             {},
             lambda rsp: decodelist(rsp[:-1]),
             ),
+          'known': (
+            {'nodes': encodelist},
+            lambda rsp: [bool(int(f)) for f in rsp],
+            ),
           }
 
 class wirerepository(repo.repository):
@@ -106,12 +110,7 @@
         return self._single('heads')
 
     def known(self, nodes):
-        n = encodelist(nodes)
-        d = self._call("known", nodes=n)
-        try:
-            return [bool(int(f)) for f in d]
-        except:
-            self._abort(error.ResponseError(_("unexpected response:"), d))
+        return self._single('known', nodes=nodes)
 
     def branchmap(self):
         d = self._call("branchmap")
diff --git a/tests/test-http-proxy.t b/tests/test-http-proxy.t
--- a/tests/test-http-proxy.t
+++ b/tests/test-http-proxy.t
@@ -102,22 +102,22 @@
   * - - [*] "GET http://localhost:$HGPORT/?cmd=stream_out HTTP/1.1" - - (glob)
   * - - [*] "GET http://localhost:$HGPORT/?cmd=listkeys&namespace=bookmarks HTTP/1.1" - - (glob)
   * - - [*] "GET http://localhost:$HGPORT/?cmd=capabilities HTTP/1.1" - - (glob)
-  * - - [*] "GET http://localhost:$HGPORT/?cmd=heads HTTP/1.1" - - (glob)
+  * - - [*] "GET http://localhost:$HGPORT/?cmd=batch&cmds=heads+%3Bknown+nodes%3D0000000000000000000000000000000000000000 HTTP/1.1" - - (glob)
   * - - [*] "GET http://localhost:$HGPORT/?cmd=changegroupdiff&common=0000000000000000000000000000000000000000&heads=83180e7845de420a1bb46896fd5fe05294f8d629 HTTP/1.1" - - (glob)
   * - - [*] "GET http://localhost:$HGPORT/?cmd=listkeys&namespace=bookmarks HTTP/1.1" - - (glob)
   * - - [*] "GET http://localhost:$HGPORT/?cmd=listkeys&namespace=bookmarks HTTP/1.1" - - (glob)
   * - - [*] "GET http://localhost:$HGPORT/?cmd=capabilities HTTP/1.1" - - (glob)
-  * - - [*] "GET http://localhost:$HGPORT/?cmd=heads HTTP/1.1" - - (glob)
+  * - - [*] "GET http://localhost:$HGPORT/?cmd=batch&cmds=heads+%3Bknown+nodes%3D0000000000000000000000000000000000000000 HTTP/1.1" - - (glob)
   * - - [*] "GET http://localhost:$HGPORT/?cmd=changegroupdiff&common=0000000000000000000000000000000000000000&heads=83180e7845de420a1bb46896fd5fe05294f8d629 HTTP/1.1" - - (glob)
   * - - [*] "GET http://localhost:$HGPORT/?cmd=listkeys&namespace=bookmarks HTTP/1.1" - - (glob)
   * - - [*] "GET http://localhost:$HGPORT/?cmd=listkeys&namespace=bookmarks HTTP/1.1" - - (glob)
   * - - [*] "GET http://localhost:$HGPORT/?cmd=capabilities HTTP/1.1" - - (glob)
-  * - - [*] "GET http://localhost:$HGPORT/?cmd=heads HTTP/1.1" - - (glob)
+  * - - [*] "GET http://localhost:$HGPORT/?cmd=batch&cmds=heads+%3Bknown+nodes%3D0000000000000000000000000000000000000000 HTTP/1.1" - - (glob)
   * - - [*] "GET http://localhost:$HGPORT/?cmd=changegroupdiff&common=0000000000000000000000000000000000000000&heads=83180e7845de420a1bb46896fd5fe05294f8d629 HTTP/1.1" - - (glob)
   * - - [*] "GET http://localhost:$HGPORT/?cmd=listkeys&namespace=bookmarks HTTP/1.1" - - (glob)
   * - - [*] "GET http://localhost:$HGPORT/?cmd=listkeys&namespace=bookmarks HTTP/1.1" - - (glob)
   * - - [*] "GET http://localhost:$HGPORT/?cmd=capabilities HTTP/1.1" - - (glob)
-  * - - [*] "GET http://localhost:$HGPORT/?cmd=heads HTTP/1.1" - - (glob)
+  * - - [*] "GET http://localhost:$HGPORT/?cmd=batch&cmds=heads+%3Bknown+nodes%3D0000000000000000000000000000000000000000 HTTP/1.1" - - (glob)
   * - - [*] "GET http://localhost:$HGPORT/?cmd=changegroupdiff&common=0000000000000000000000000000000000000000&heads=83180e7845de420a1bb46896fd5fe05294f8d629 HTTP/1.1" - - (glob)
   * - - [*] "GET http://localhost:$HGPORT/?cmd=listkeys&namespace=bookmarks HTTP/1.1" - - (glob)
   * - - [*] "GET http://localhost:$HGPORT/?cmd=listkeys&namespace=bookmarks HTTP/1.1" - - (glob)
diff --git a/tests/test-schemes.t b/tests/test-schemes.t
--- a/tests/test-schemes.t
+++ b/tests/test-schemes.t
@@ -27,9 +27,8 @@
   using http://localhost:$HGPORT/
   sending capabilities command
   comparing with parts://localhost
-  sending heads command
+  sending batch command
   searching for changes
-  sending known command
   no changes found
   [1]
 


More information about the Mercurial-devel mailing list