mercurial/wireproto.py
changeset 27246 b288fb2724bf
parent 27243 3abee2ba27af
child 27633 37d7cf569cf3
equal deleted inserted replaced
27244:709977a4fc9d 27246:b288fb2724bf
    27     peer,
    27     peer,
    28     pushkey as pushkeymod,
    28     pushkey as pushkeymod,
    29     streamclone,
    29     streamclone,
    30     util,
    30     util,
    31 )
    31 )
       
    32 
       
    33 bundle2required = _(
       
    34     'incompatible Mercurial client; bundle2 required\n'
       
    35     '(see https://www.mercurial-scm.org/wiki/IncompatibleClient)\n')
    32 
    36 
    33 class abstractserverproto(object):
    37 class abstractserverproto(object):
    34     """abstract class that summarizes the protocol API
    38     """abstract class that summarizes the protocol API
    35 
    39 
    36     Used as reference and documentation.
    40     Used as reference and documentation.
   485     if others:
   489     if others:
   486         sys.stderr.write("warning: %s ignored unexpected arguments %s\n"
   490         sys.stderr.write("warning: %s ignored unexpected arguments %s\n"
   487                          % (cmd, ",".join(others)))
   491                          % (cmd, ",".join(others)))
   488     return opts
   492     return opts
   489 
   493 
       
   494 def bundle1allowed(ui, action):
       
   495     """Whether a bundle1 operation is allowed from the server."""
       
   496     v = ui.configbool('server', 'bundle1.%s' % action, None)
       
   497     if v is not None:
       
   498         return v
       
   499 
       
   500     return ui.configbool('server', 'bundle1', True)
       
   501 
   490 # list of commands
   502 # list of commands
   491 commands = {}
   503 commands = {}
   492 
   504 
   493 def wireprotocommand(name, args=''):
   505 def wireprotocommand(name, args=''):
   494     """decorator for wire protocol command"""
   506     """decorator for wire protocol command"""
   650             else:
   662             else:
   651                 opts[k] = bool(v)
   663                 opts[k] = bool(v)
   652         elif keytype != 'plain':
   664         elif keytype != 'plain':
   653             raise KeyError('unknown getbundle option type %s'
   665             raise KeyError('unknown getbundle option type %s'
   654                            % keytype)
   666                            % keytype)
       
   667 
       
   668     if not bundle1allowed(repo.ui, 'pull'):
       
   669         if not exchange.bundle2requested(opts.get('bundlecaps')):
       
   670             return ooberror(bundle2required)
       
   671 
   655     cg = exchange.getbundle(repo, 'serve', **opts)
   672     cg = exchange.getbundle(repo, 'serve', **opts)
   656     return streamres(proto.groupchunks(cg))
   673     return streamres(proto.groupchunks(cg))
   657 
   674 
   658 @wireprotocommand('heads')
   675 @wireprotocommand('heads')
   659 def heads(repo, proto):
   676 def heads(repo, proto):
   761         r = 0
   778         r = 0
   762         try:
   779         try:
   763             proto.getfile(fp)
   780             proto.getfile(fp)
   764             fp.seek(0)
   781             fp.seek(0)
   765             gen = exchange.readbundle(repo.ui, fp, None)
   782             gen = exchange.readbundle(repo.ui, fp, None)
       
   783             if (isinstance(gen, changegroupmod.cg1unpacker)
       
   784                 and not bundle1allowed(repo.ui, 'push')):
       
   785                 return ooberror(bundle2required)
       
   786 
   766             r = exchange.unbundle(repo, gen, their_heads, 'serve',
   787             r = exchange.unbundle(repo, gen, their_heads, 'serve',
   767                                   proto._client())
   788                                   proto._client())
   768             if util.safehasattr(r, 'addpart'):
   789             if util.safehasattr(r, 'addpart'):
   769                 # The return looks streamable, we are in the bundle2 case and
   790                 # The return looks streamable, we are in the bundle2 case and
   770                 # should return a stream.
   791                 # should return a stream.