comparison 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
comparison
equal deleted inserted replaced
27632:9fea6b38a8da 27633:37d7cf569cf3
489 if others: 489 if others:
490 sys.stderr.write("warning: %s ignored unexpected arguments %s\n" 490 sys.stderr.write("warning: %s ignored unexpected arguments %s\n"
491 % (cmd, ",".join(others))) 491 % (cmd, ",".join(others)))
492 return opts 492 return opts
493 493
494 def bundle1allowed(ui, action): 494 def bundle1allowed(repo, action):
495 """Whether a bundle1 operation is allowed from the server.""" 495 """Whether a bundle1 operation is allowed from the server.
496
497 Priority is:
498
499 1. server.bundle1gd.<action> (if generaldelta active)
500 2. server.bundle1.<action>
501 3. server.bundle1gd (if generaldelta active)
502 4. server.bundle1
503 """
504 ui = repo.ui
505 gd = 'generaldelta' in repo.requirements
506
507 if gd:
508 v = ui.configbool('server', 'bundle1gd.%s' % action, None)
509 if v is not None:
510 return v
511
496 v = ui.configbool('server', 'bundle1.%s' % action, None) 512 v = ui.configbool('server', 'bundle1.%s' % action, None)
497 if v is not None: 513 if v is not None:
498 return v 514 return v
515
516 if gd:
517 v = ui.configbool('server', 'bundle1gd', None)
518 if v is not None:
519 return v
499 520
500 return ui.configbool('server', 'bundle1', True) 521 return ui.configbool('server', 'bundle1', True)
501 522
502 # list of commands 523 # list of commands
503 commands = {} 524 commands = {}
663 opts[k] = bool(v) 684 opts[k] = bool(v)
664 elif keytype != 'plain': 685 elif keytype != 'plain':
665 raise KeyError('unknown getbundle option type %s' 686 raise KeyError('unknown getbundle option type %s'
666 % keytype) 687 % keytype)
667 688
668 if not bundle1allowed(repo.ui, 'pull'): 689 if not bundle1allowed(repo, 'pull'):
669 if not exchange.bundle2requested(opts.get('bundlecaps')): 690 if not exchange.bundle2requested(opts.get('bundlecaps')):
670 return ooberror(bundle2required) 691 return ooberror(bundle2required)
671 692
672 cg = exchange.getbundle(repo, 'serve', **opts) 693 cg = exchange.getbundle(repo, 'serve', **opts)
673 return streamres(proto.groupchunks(cg)) 694 return streamres(proto.groupchunks(cg))
779 try: 800 try:
780 proto.getfile(fp) 801 proto.getfile(fp)
781 fp.seek(0) 802 fp.seek(0)
782 gen = exchange.readbundle(repo.ui, fp, None) 803 gen = exchange.readbundle(repo.ui, fp, None)
783 if (isinstance(gen, changegroupmod.cg1unpacker) 804 if (isinstance(gen, changegroupmod.cg1unpacker)
784 and not bundle1allowed(repo.ui, 'push')): 805 and not bundle1allowed(repo, 'push')):
785 return ooberror(bundle2required) 806 return ooberror(bundle2required)
786 807
787 r = exchange.unbundle(repo, gen, their_heads, 'serve', 808 r = exchange.unbundle(repo, gen, their_heads, 'serve',
788 proto._client()) 809 proto._client())
789 if util.safehasattr(r, 'addpart'): 810 if util.safehasattr(r, 'addpart'):