Patchwork [4,of,4,V3] clonebundle: make it possible to retrieve the initial bundle through largefile

login
register
mail settings
Submitter Boris Feld
Date Jan. 8, 2018, 9:16 p.m.
Message ID <6b3878f98472ce1bdc82.1515446208@FB>
Download mbox | patch
Permalink /patch/26620/
State Accepted
Headers show

Comments

Boris Feld - Jan. 8, 2018, 9:16 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1513861091 -3600
#      Thu Dec 21 13:58:11 2017 +0100
# Node ID 6b3878f98472ce1bdc82e50a69bb32500c43c848
# Parent  18db7b5d796d31fbced9d41dd50a61d0e62e6fcb
# EXP-Topic largefile-url
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 6b3878f98472
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.

Patch

diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -659,6 +659,9 @@  def clone(ui, peeropts, source, dest=Non
                 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
diff --git a/tests/test-clonebundles.t b/tests/test-clonebundles.t
--- a/tests/test-clonebundles.t
+++ b/tests/test-clonebundles.t
@@ -517,3 +517,30 @@  A manifest with a gzip bundle and a stre
   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