clonebundles: make advertisement work with <3.6 servers (bug 1217155); r=smacleod
authorGregory Szorc <gps@mozilla.com>
Fri, 23 Oct 2015 21:16:04 +0100
changeset 3208 ca2878733e98e6ef188f3ed589b38526304ea42e
parent 3207 fece840df94511da1672e27d897f942672b647d9
child 3209 4246ddb54f526958e1cfa40a0d4c6dff8882e9a3
push id1203
push usergszorc@mozilla.com
push dateFri, 23 Oct 2015 20:30:07 +0000
treeherderversion-control-tools@fd8f2df5ffe1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmacleod
bugs1217155
clonebundles: make advertisement work with <3.6 servers (bug 1217155); r=smacleod There are two issues preventing clonebundles' built-in advertisements from working in <3.6 servers: 1) "cbattempted" argument to "getbundle" wire protocol command isn't defined, leading the server to drop it. 2) parsing of boolean arguments is incorrect (this was fixed in 3e7f675628ad) This patch hacks our vendored copy of clonebundles.py to work around both these issues. We throw an exception if a 3.6+ server is detected. This way, we catch accidental usage of our vendored clonebundles.py when we upgrade hg.mozilla.org to 3.6. A test checking for proper behavior has been added.
hgext/bundleclone/tests/test-clonebundles-compat.t
hgserver/clonebundles.py
hgserver/tests/test-clonebundles.t
--- a/hgext/bundleclone/tests/test-clonebundles-compat.t
+++ b/hgext/bundleclone/tests/test-clonebundles-compat.t
@@ -164,8 +164,14 @@ with different file headers.
   streaming all changes
   4 files to transfer, 613 bytes of data
   transferred 613 bytes in * seconds (*) (glob)
   finishing applying bundle; pulling
   searching for changes
   no changes found
 
 #endif
+
+Hacked up clonebundles extension should fail on 3.6+
+
+  $ $TESTDIR/venv/mercurials/@/bin/hg --config extensions.clonebundles=$TESTDIR/hgserver/clonebundles.py version
+  abort: use built-in clonebundles extension with Mercurial 3.6+
+  [255]
--- a/hgserver/clonebundles.py
+++ b/hgserver/clonebundles.py
@@ -188,16 +188,17 @@ experimental.clonebundleprefers
 
    If not defined, the order in the manifest will be used and the first
    available bundle will be downloaded.
 """
 
 from mercurial.i18n import _
 from mercurial.node import nullid
 from mercurial import (
+    error,
     exchange,
     extensions,
     wireproto,
 )
 
 testedwith = 'internal'
 
 def capabilities(orig, repo, proto):
@@ -241,17 +242,17 @@ def advertiseclonebundlespart(bundler, r
     if not kwargs.get('cg', True):
         return
 
     # And when the client supports clone bundles.
     if cbattempted is None:
         return
 
     # And when the client didn't attempt a clone bundle as part of this pull.
-    if cbattempted:
+    if cbattempted != '0':
         return
 
     # And when a full clone is requested.
     # Note: client should not send "cbattempted" for regular pulls. This check
     # is defense in depth.
     if common and common != [nullid]:
         return
 
@@ -259,8 +260,16 @@ def advertiseclonebundlespart(bundler, r
             'that should enable faster and more reliable cloning\n'
             'help test it by setting the "experimental.clonebundles" config '
             'flag to "true"')
 
     bundler.newpart('output', data=msg)
 
 def extsetup(ui):
     extensions.wrapfunction(wireproto, '_capabilities', capabilities)
+
+    # MOZILLA HACK
+    # This enables the extension to work with hg < 3.6.
+    if 'cbattempted' in wireproto.gboptsmap:
+        raise error.Abort('use built-in clonebundles extension with '
+                          'Mercurial 3.6+')
+
+    wireproto.gboptsmap['cbattempted'] = 'plain'
new file mode 100644
--- /dev/null
+++ b/hgserver/tests/test-clonebundles.t
@@ -0,0 +1,63 @@
+#require hgmodocker
+
+  $ . $TESTDIR/hgserver/tests/helpers.sh
+  $ hgmoenv
+  $ standarduser
+
+Create and seed repository
+
+  $ hgmo create-repo mozilla-central 1
+
+  $ hg clone ssh://${SSH_SERVER}:${SSH_PORT}/mozilla-central > /dev/null
+  $ cd mozilla-central
+  $ touch foo
+  $ hg -q commit -A -m initial
+  $ hg push > /dev/null
+  $ cd ..
+
+Create a clonebundles manifest
+
+  $ hgmo exec hgssh sudo -u hg /repo/hg/venv_tools/bin/python /repo/hg/version-control-tools/scripts/generate-hg-s3-bundles --no-upload mozilla-central &> /dev/null
+
+Cloning with a client that supports clonebundles should advertise the
+feature
+
+#if hg36+
+
+  $ hg clone -U ${HGWEB_0_URL}mozilla-central clonebundles-advertise
+  requesting all changes
+  remote: this server supports the experimental "clone bundles" feature that should enable faster and more reliable cloning
+  remote: help test it by setting the "experimental.clonebundles" config flag to "true"
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+
+#else
+
+  $ hg clone -U ${HGWEB_0_URL}mozilla-central clonebundles-no-support
+  requesting all changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+
+#endif
+
+We shouldn't see the message if we attempted to use clonebundles
+
+#if hg36+
+
+  $ hg --config experimental.clonebundles=true --config ui.clonebundlefallback=true clone -U ${HGWEB_0_URL}mozilla-central clonebundles-no-advertise
+  applying clone bundle from https://hg.cdn.mozilla.net/mozilla-central/96ee1d7354c4ad7372047672c36a1f561e3a6a4c.gzip.hg
+  HTTP error fetching bundle: HTTP Error 403: Forbidden
+  falling back to normal clone
+  requesting all changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+
+#endif
+
+  $ hgmo stop