changeset 27633:37d7cf569cf3

wireproto: support disabling bundle1 only if repo is generaldelta I recently implemented the server.bundle1* options to control whether bundle1 exchange is allowed. After thinking about Mozilla's strategy for handling generaldelta rollout a bit more, I think server operators need an additional lever: disable bundle1 if and only if the repo is generaldelta. bundle1 exchange for non-generaldelta repos will not have the potential for CPU explosion that generaldelta repos do. Therefore, it makes sense for server operators to continue to allow bundle1 exchange for non-generaldelta repos without having to set a per-repo hgrc option to change the policy depending on whether the repo is generaldelta. This patch introduces a new set of options to control bundle1 behavior for generaldelta repos. These options enable server operators to limit bundle1 restrictions to the class of repos that can be performance issues. It also allows server operators to tie bundle1 access to store format. In many server environments (including Mozilla's), legacy repos will not be generaldelta and new repos will or might be. New repos often aren't bound by legacy access requirements, so setting a global policy that disallows access to new/generaldelta repos via bundle1 could be a reasonable policy in many server environments. This patch makes this policy very easy to implement (modify global hgrc, add options to existing generaldelta repos to grandfather them in).
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 20 Dec 2015 11:56:24 -0800
parents 9fea6b38a8da
children a1eff44c432b
files mercurial/help/config.txt mercurial/wireproto.py tests/test-bundle2-exchange.t
diffstat 3 files changed, 118 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/help/config.txt	Sat Jan 02 15:14:55 2016 -0800
+++ b/mercurial/help/config.txt	Sun Dec 20 11:56:24 2015 -0800
@@ -1345,14 +1345,26 @@
     Whether to allow clients to push and pull using the legacy bundle1
     exchange format. (default: True)
 
+``bundle1gd``
+    Like ``bundle1` but only used if the repository is using the
+    *generaldelta* storage format. (default: True)
+
 ``bundle1.push``
     Whether to allow clients to push using the legacy bundle1 exchange
     format. (default: True)
 
+``bundle1gd.push``
+    Like ``bundle1.push` but only used if the repository is using the
+    *generaldelta* storage format. (default: True)
+
 ``bundle1.pull``
     Whether to allow clients to pull using the legacy bundle1 exchange
     format. (default: True)
 
+``bundle1gd.pull``
+    Like ``bundle1.pull` but only used if the repository is using the
+    *generaldelta* storage format. (default: True)
+
     Large repositories using the *generaldelta* storage format should
     consider setting this option because converting *generaldelta*
     repositories to the exchange format required by the bundle1 data
--- a/mercurial/wireproto.py	Sat Jan 02 15:14:55 2016 -0800
+++ b/mercurial/wireproto.py	Sun Dec 20 11:56:24 2015 -0800
@@ -491,12 +491,33 @@
                          % (cmd, ",".join(others)))
     return opts
 
-def bundle1allowed(ui, action):
-    """Whether a bundle1 operation is allowed from the server."""
+def bundle1allowed(repo, action):
+    """Whether a bundle1 operation is allowed from the server.
+
+    Priority is:
+
+    1. server.bundle1gd.<action> (if generaldelta active)
+    2. server.bundle1.<action>
+    3. server.bundle1gd (if generaldelta active)
+    4. server.bundle1
+    """
+    ui = repo.ui
+    gd = 'generaldelta' in repo.requirements
+
+    if gd:
+        v = ui.configbool('server', 'bundle1gd.%s' % action, None)
+        if v is not None:
+            return v
+
     v = ui.configbool('server', 'bundle1.%s' % action, None)
     if v is not None:
         return v
 
+    if gd:
+        v = ui.configbool('server', 'bundle1gd', None)
+        if v is not None:
+            return v
+
     return ui.configbool('server', 'bundle1', True)
 
 # list of commands
@@ -665,7 +686,7 @@
             raise KeyError('unknown getbundle option type %s'
                            % keytype)
 
-    if not bundle1allowed(repo.ui, 'pull'):
+    if not bundle1allowed(repo, 'pull'):
         if not exchange.bundle2requested(opts.get('bundlecaps')):
             return ooberror(bundle2required)
 
@@ -781,7 +802,7 @@
             fp.seek(0)
             gen = exchange.readbundle(repo.ui, fp, None)
             if (isinstance(gen, changegroupmod.cg1unpacker)
-                and not bundle1allowed(repo.ui, 'push')):
+                and not bundle1allowed(repo, 'push')):
                 return ooberror(bundle2required)
 
             r = exchange.unbundle(repo, gen, their_heads, 'serve',
--- a/tests/test-bundle2-exchange.t	Sat Jan 02 15:14:55 2016 -0800
+++ b/tests/test-bundle2-exchange.t	Sun Dec 20 11:56:24 2015 -0800
@@ -977,6 +977,51 @@
   (see https://www.mercurial-scm.org/wiki/IncompatibleClient)
   [255]
   $ killdaemons.py
+  $ cd ..
+
+bundle1 can still pull non-generaldelta repos when generaldelta bundle1 disabled
+
+  $ hg --config format.usegeneraldelta=false init notgdserver
+  $ cd notgdserver
+  $ cat > .hg/hgrc << EOF
+  > [server]
+  > bundle1gd.pull = false
+  > EOF
+
+  $ touch foo
+  $ hg -q commit -A -m initial
+  $ hg serve -p $HGPORT -d --pid-file=hg.pid
+  $ cat hg.pid >> $DAEMON_PIDS
+
+  $ hg --config experimental.bundle2-exp=false clone http://localhost:$HGPORT/ not-bundle2-1
+  requesting all changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+  updating to branch default
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+  $ killdaemons.py
+  $ cd ../bundle2onlyserver
+
+bundle1 pull can be disabled for generaldelta repos only
+
+  $ cat > .hg/hgrc << EOF
+  > [server]
+  > bundle1gd.pull = false
+  > EOF
+
+  $ hg serve -p $HGPORT -d --pid-file=hg.pid
+  $ cat hg.pid >> $DAEMON_PIDS
+  $ hg --config experimental.bundle2-exp=false clone http://localhost:$HGPORT/ not-bundle2
+  requesting all changes
+  abort: remote error:
+  incompatible Mercurial client; bundle2 required
+  (see https://www.mercurial-scm.org/wiki/IncompatibleClient)
+  [255]
+
+  $ killdaemons.py
 
 Verify the global server.bundle1 option works
 
@@ -994,6 +1039,42 @@
   [255]
   $ killdaemons.py
 
+  $ cat > .hg/hgrc << EOF
+  > [server]
+  > bundle1gd = false
+  > EOF
+  $ hg serve -p $HGPORT -d --pid-file=hg.pid
+  $ cat hg.pid >> $DAEMON_PIDS
+
+  $ hg --config experimental.bundle2-exp=false clone http://localhost:$HGPORT/ not-bundle2
+  requesting all changes
+  abort: remote error:
+  incompatible Mercurial client; bundle2 required
+  (see https://www.mercurial-scm.org/wiki/IncompatibleClient)
+  [255]
+
+  $ killdaemons.py
+
+  $ cd ../notgdserver
+  $ cat > .hg/hgrc << EOF
+  > [server]
+  > bundle1gd = false
+  > EOF
+  $ hg serve -p $HGPORT -d --pid-file=hg.pid
+  $ cat hg.pid >> $DAEMON_PIDS
+
+  $ hg --config experimental.bundle2-exp=false clone http://localhost:$HGPORT/ not-bundle2-2
+  requesting all changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+  updating to branch default
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+  $ killdaemons.py
+  $ cd ../bundle2onlyserver
+
 Verify bundle1 pushes can be disabled
 
   $ cat > .hg/hgrc << EOF