diff mercurial/wireproto.py @ 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 b288fb2724bf
children 176736afa886
line wrap: on
line diff
--- 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',