mercurial/wireproto.py
changeset 37485 0b7475ea38cf
parent 37414 2d965bfeb8f6
child 37486 6847542bb8d7
equal deleted inserted replaced
37484:c22fd3c4c23e 37485:0b7475ea38cf
   516     transportversion = wireprototypes.TRANSPORTS[proto.name]['version']
   516     transportversion = wireprototypes.TRANSPORTS[proto.name]['version']
   517     commandtable = commandsv2 if transportversion == 2 else commands
   517     commandtable = commandsv2 if transportversion == 2 else commands
   518     func, spec = commandtable[command]
   518     func, spec = commandtable[command]
   519 
   519 
   520     args = proto.getargs(spec)
   520     args = proto.getargs(spec)
   521     return func(repo, proto, *args)
   521 
       
   522     # Version 1 protocols define arguments as a list. Version 2 uses a dict.
       
   523     if isinstance(args, list):
       
   524         return func(repo, proto, *args)
       
   525     elif isinstance(args, dict):
       
   526         return func(repo, proto, **args)
       
   527     else:
       
   528         raise error.ProgrammingError('unexpected type returned from '
       
   529                                      'proto.getargs(): %s' % type(args))
   522 
   530 
   523 def options(cmd, keys, others):
   531 def options(cmd, keys, others):
   524     opts = {}
   532     opts = {}
   525     for k in keys:
   533     for k in keys:
   526         if k in others:
   534         if k in others:
   994         prefercompressed = False
  1002         prefercompressed = False
   995 
  1003 
   996     return wireprototypes.streamres(
  1004     return wireprototypes.streamres(
   997         gen=chunks, prefer_uncompressed=not prefercompressed)
  1005         gen=chunks, prefer_uncompressed=not prefercompressed)
   998 
  1006 
   999 @wireprotocommand('heads', permission='pull')
  1007 @wireprotocommand('heads', permission='pull', transportpolicy=POLICY_V1_ONLY)
  1000 def heads(repo, proto):
  1008 def heads(repo, proto):
  1001     h = repo.heads()
  1009     h = repo.heads()
  1002     return wireprototypes.bytesresponse(encodelist(h) + '\n')
  1010     return wireprototypes.bytesresponse(encodelist(h) + '\n')
  1003 
  1011 
  1004 @wireprotocommand('hello', permission='pull')
  1012 @wireprotocommand('hello', permission='pull')
  1195                                                    manargs, advargs))
  1203                                                    manargs, advargs))
  1196             except error.PushRaced as exc:
  1204             except error.PushRaced as exc:
  1197                 bundler.newpart('error:pushraced',
  1205                 bundler.newpart('error:pushraced',
  1198                                 [('message', stringutil.forcebytestr(exc))])
  1206                                 [('message', stringutil.forcebytestr(exc))])
  1199             return wireprototypes.streamreslegacy(gen=bundler.getchunks())
  1207             return wireprototypes.streamreslegacy(gen=bundler.getchunks())
       
  1208 
       
  1209 # Wire protocol version 2 commands only past this point.
       
  1210 
       
  1211 @wireprotocommand('heads', args='publiconly', permission='pull',
       
  1212                   transportpolicy=POLICY_V2_ONLY)
       
  1213 def headsv2(repo, proto, publiconly=False):
       
  1214     if publiconly:
       
  1215         repo = repo.filtered('immutable')
       
  1216 
       
  1217     return wireprototypes.cborresponse(repo.heads())