clonebundle: make it possible to retrieve the initial bundle through largefile
authorBoris Feld <boris.feld@octobus.net>
Thu, 21 Dec 2017 13:58:11 +0100
changeset 35565 bdae51a83dfb
parent 35564 cf841f2b5a72
child 35566 baca93a47992
clonebundle: make it possible to retrieve the initial bundle through largefile By setting the default path early enough, we make it possible to retrieve a clone bundle as a largefile from the repository we are cloning. But... why? Clone bundle is a great feature to speeds up clone of large repository. However one of the main obstacle for clone bundle deployment is the authentication scheme. For non public project, just putting a static file on some random CDN is not an option as we have to make sure people have the proper permission to retrieves the bundle. On the other hand, 'largefiles' already have all the necessary logic to serve arbitrary binary files -after- an authentication checks. So reusing an existing large file infrastructure can be a significant shortcut to clone bundle in this kind of closed environment. The idea might seems strange, but the necessary update to the large file extensions are quite small while the benefits are huge. In addition, since all the extra logic live in the 'largefiles' extensions, core does not have to know anything about it.
mercurial/hg.py
tests/test-clonebundles.t
--- a/mercurial/hg.py	Thu Dec 21 13:57:57 2017 +0100
+++ b/mercurial/hg.py	Thu Dec 21 13:58:11 2017 +0100
@@ -659,6 +659,9 @@
                 checkout = revs[0]
             local = destpeer.local()
             if local:
+                u = util.url(abspath)
+                defaulturl = bytes(u)
+                local.ui.setconfig('paths', 'default', defaulturl, 'clone')
                 if not stream:
                     if pull:
                         stream = False
--- a/tests/test-clonebundles.t	Thu Dec 21 13:57:57 2017 +0100
+++ b/tests/test-clonebundles.t	Thu Dec 21 13:58:11 2017 +0100
@@ -517,3 +517,30 @@
   transferred 613 bytes in * seconds (*) (glob)
   searching for changes
   no changes found
+
+Test clone bundle retrieved through bundle2
+
+  $ cat << EOF >> $HGRCPATH
+  > [extensions]
+  > largefiles=
+  > EOF
+  $ killdaemons.py
+  $ hg -R server serve -d -p $HGPORT --pid-file hg.pid --accesslog access.log
+  $ cat hg.pid >> $DAEMON_PIDS
+
+  $ hg -R server debuglfput gz-a.hg
+  f6eca29e25359f6a92f1ea64527cdcf1b5abe62a
+
+  $ cat > server/.hg/clonebundles.manifest << EOF
+  > largefile://f6eca29e25359f6a92f1ea64527cdcf1b5abe62a BUNDLESPEC=gzip-v2
+  > EOF
+
+  $ hg clone -U http://localhost:$HGPORT largefile-provided --traceback
+  applying clone bundle from largefile://f6eca29e25359f6a92f1ea64527cdcf1b5abe62a
+  adding changesets
+  adding manifests
+  adding file changes
+  added 2 changesets with 2 changes to 2 files
+  finished applying clone bundle
+  searching for changes
+  no changes found