httprepo: use caps instead of between for compat check
We usually query the capabilities at some point anyway so this way the first roundtrip
actually does useful work.
--- a/mercurial/httprepo.py Sat Mar 12 18:48:30 2011 +0100
+++ b/mercurial/httprepo.py Sat Mar 12 18:29:02 2011 +0100
@@ -52,10 +52,13 @@
# look up capabilities only when needed
+ def _fetchcaps(self):
+ self.caps = set(self._call('capabilities').split())
+
def get_caps(self):
if self.caps is None:
try:
- self.caps = set(self._call('capabilities').split())
+ self._fetchcaps()
except error.RepoError:
self.caps = set()
self.ui.debug('capabilities: %s\n' %
@@ -195,7 +198,13 @@
inst = httpsrepository(ui, path)
else:
inst = httprepository(ui, path)
- inst.between([(nullid, nullid)])
+ try:
+ # Try to do useful work when checking compatibility.
+ # Usually saves a roundtrip since we want the caps anyway.
+ inst._fetchcaps()
+ except error.RepoError:
+ # No luck, try older compatibility check.
+ inst.between([(nullid, nullid)])
return inst
except error.RepoError:
ui.note('(falling back to static-http)\n')
--- a/tests/test-http-proxy.t Sat Mar 12 18:48:30 2011 +0100
+++ b/tests/test-http-proxy.t Sat Mar 12 18:29:02 2011 +0100
@@ -98,27 +98,22 @@
updating to branch default
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ cat proxy.log
- * - - [*] "GET http://localhost:$HGPORT/?cmd=between&pairs=0000000000000000000000000000000000000000-0000000000000000000000000000000000000000 HTTP/1.1" - - (glob)
* - - [*] "GET http://localhost:$HGPORT/?cmd=capabilities HTTP/1.1" - - (glob)
* - - [*] "GET http://localhost:$HGPORT/?cmd=stream_out HTTP/1.1" - - (glob)
- * - - [*] "GET http://localhost:$HGPORT/?cmd=between&pairs=0000000000000000000000000000000000000000-0000000000000000000000000000000000000000 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=changegroup&roots=0000000000000000000000000000000000000000 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=listkeys&namespace=bookmarks HTTP/1.1" - - (glob)
- * - - [*] "GET http://localhost:$HGPORT/?cmd=between&pairs=0000000000000000000000000000000000000000-0000000000000000000000000000000000000000 HTTP/1.1" - - (glob)
* - - [*] "GET http://localhost:$HGPORT/?cmd=heads HTTP/1.1" - - (glob)
* - - [*] "GET http://localhost:$HGPORT/?cmd=changegroup&roots=0000000000000000000000000000000000000000 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=listkeys&namespace=bookmarks HTTP/1.1" - - (glob)
- * - - [*] "GET http://localhost:$HGPORT/?cmd=between&pairs=0000000000000000000000000000000000000000-0000000000000000000000000000000000000000 HTTP/1.1" - - (glob)
* - - [*] "GET http://localhost:$HGPORT/?cmd=heads HTTP/1.1" - - (glob)
* - - [*] "GET http://localhost:$HGPORT/?cmd=changegroup&roots=0000000000000000000000000000000000000000 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=listkeys&namespace=bookmarks HTTP/1.1" - - (glob)
- * - - [*] "GET http://localhost:$HGPORT/?cmd=between&pairs=0000000000000000000000000000000000000000-0000000000000000000000000000000000000000 HTTP/1.1" - - (glob)
* - - [*] "GET http://localhost:$HGPORT/?cmd=heads HTTP/1.1" - - (glob)
* - - [*] "GET http://localhost:$HGPORT/?cmd=changegroup&roots=0000000000000000000000000000000000000000 HTTP/1.1" - - (glob)
- * - - [*] "GET http://localhost:$HGPORT/?cmd=capabilities HTTP/1.1" - - (glob)
* - - [*] "GET http://localhost:$HGPORT/?cmd=listkeys&namespace=bookmarks HTTP/1.1" - - (glob)
--- a/tests/test-schemes.t Sat Mar 12 18:48:30 2011 +0100
+++ b/tests/test-schemes.t Sat Mar 12 18:29:02 2011 +0100
@@ -25,7 +25,7 @@
$ hg incoming --debug parts://localhost
using http://localhost:$HGPORT/
- sending between command
+ sending capabilities command
comparing with parts://localhost
sending heads command
searching for changes