mercurial/debugcommands.py
changeset 48526 04688c51f81f
parent 48187 b669e40fbbd6
child 48556 ce8c82a5cd65
equal deleted inserted replaced
48525:d6c53b40b078 48526:04688c51f81f
    89     url as urlmod,
    89     url as urlmod,
    90     util,
    90     util,
    91     vfs as vfsmod,
    91     vfs as vfsmod,
    92     wireprotoframing,
    92     wireprotoframing,
    93     wireprotoserver,
    93     wireprotoserver,
    94     wireprotov2peer,
       
    95 )
    94 )
    96 from .interfaces import repository
    95 from .interfaces import repository
    97 from .utils import (
    96 from .utils import (
    98     cborutil,
    97     cborutil,
    99     compression,
    98     compression,
  4350     and connect to that. By default, the connection will perform a handshake
  4349     and connect to that. By default, the connection will perform a handshake
  4351     and establish an appropriate peer instance.
  4350     and establish an appropriate peer instance.
  4352 
  4351 
  4353     ``--peer`` can be used to bypass the handshake protocol and construct a
  4352     ``--peer`` can be used to bypass the handshake protocol and construct a
  4354     peer instance using the specified class type. Valid values are ``raw``,
  4353     peer instance using the specified class type. Valid values are ``raw``,
  4355     ``http2``, ``ssh1``, and ``ssh2``. ``raw`` instances only allow sending
  4354     ``ssh1``. ``raw`` instances only allow sending raw data payloads and
  4356     raw data payloads and don't support higher-level command actions.
  4355     don't support higher-level command actions.
  4357 
  4356 
  4358     ``--noreadstderr`` can be used to disable automatic reading from stderr
  4357     ``--noreadstderr`` can be used to disable automatic reading from stderr
  4359     of the peer (for SSH connections only). Disabling automatic reading of
  4358     of the peer (for SSH connections only). Disabling automatic reading of
  4360     stderr is useful for making output more deterministic.
  4359     stderr is useful for making output more deterministic.
  4361 
  4360 
  4526     if opts[b'localssh'] and not repo:
  4525     if opts[b'localssh'] and not repo:
  4527         raise error.Abort(_(b'--localssh requires a repository'))
  4526         raise error.Abort(_(b'--localssh requires a repository'))
  4528 
  4527 
  4529     if opts[b'peer'] and opts[b'peer'] not in (
  4528     if opts[b'peer'] and opts[b'peer'] not in (
  4530         b'raw',
  4529         b'raw',
  4531         b'http2',
       
  4532         b'ssh1',
  4530         b'ssh1',
  4533         b'ssh2',
       
  4534     ):
  4531     ):
  4535         raise error.Abort(
  4532         raise error.Abort(
  4536             _(b'invalid value for --peer'),
  4533             _(b'invalid value for --peer'),
  4537             hint=_(b'valid values are "raw", "ssh1", and "ssh2"'),
  4534             hint=_(b'valid values are "raw" and "ssh1"'),
  4538         )
  4535         )
  4539 
  4536 
  4540     if path and opts[b'localssh']:
  4537     if path and opts[b'localssh']:
  4541         raise error.Abort(_(b'cannot specify --localssh with an explicit path'))
  4538         raise error.Abort(_(b'cannot specify --localssh with an explicit path'))
  4542 
  4539 
  4591         autoreadstderr = not opts[b'noreadstderr']
  4588         autoreadstderr = not opts[b'noreadstderr']
  4592 
  4589 
  4593         if opts[b'peer'] == b'ssh1':
  4590         if opts[b'peer'] == b'ssh1':
  4594             ui.write(_(b'creating ssh peer for wire protocol version 1\n'))
  4591             ui.write(_(b'creating ssh peer for wire protocol version 1\n'))
  4595             peer = sshpeer.sshv1peer(
  4592             peer = sshpeer.sshv1peer(
  4596                 ui,
       
  4597                 url,
       
  4598                 proc,
       
  4599                 stdin,
       
  4600                 stdout,
       
  4601                 stderr,
       
  4602                 None,
       
  4603                 autoreadstderr=autoreadstderr,
       
  4604             )
       
  4605         elif opts[b'peer'] == b'ssh2':
       
  4606             ui.write(_(b'creating ssh peer for wire protocol version 2\n'))
       
  4607             peer = sshpeer.sshv2peer(
       
  4608                 ui,
  4593                 ui,
  4609                 url,
  4594                 url,
  4610                 proc,
  4595                 proc,
  4611                 stdin,
  4596                 stdin,
  4612                 stdout,
  4597                 stdout,
  4664         if opts[b'peer'] == b'raw':
  4649         if opts[b'peer'] == b'raw':
  4665             openerargs['sendaccept'] = False
  4650             openerargs['sendaccept'] = False
  4666 
  4651 
  4667         opener = urlmod.opener(ui, authinfo, **openerargs)
  4652         opener = urlmod.opener(ui, authinfo, **openerargs)
  4668 
  4653 
  4669         if opts[b'peer'] == b'http2':
  4654         if opts[b'peer'] == b'raw':
  4670             ui.write(_(b'creating http peer for wire protocol version 2\n'))
       
  4671             # We go through makepeer() because we need an API descriptor for
       
  4672             # the peer instance to be useful.
       
  4673             maybe_silent = (
       
  4674                 ui.silent()
       
  4675                 if opts[b'nologhandshake']
       
  4676                 else util.nullcontextmanager()
       
  4677             )
       
  4678             with maybe_silent, ui.configoverride(
       
  4679                 {(b'experimental', b'httppeer.advertise-v2'): True}
       
  4680             ):
       
  4681                 peer = httppeer.makepeer(ui, path, opener=opener)
       
  4682 
       
  4683             if not isinstance(peer, httppeer.httpv2peer):
       
  4684                 raise error.Abort(
       
  4685                     _(
       
  4686                         b'could not instantiate HTTP peer for '
       
  4687                         b'wire protocol version 2'
       
  4688                     ),
       
  4689                     hint=_(
       
  4690                         b'the server may not have the feature '
       
  4691                         b'enabled or is not allowing this '
       
  4692                         b'client version'
       
  4693                     ),
       
  4694                 )
       
  4695 
       
  4696         elif opts[b'peer'] == b'raw':
       
  4697             ui.write(_(b'using raw connection to peer\n'))
  4655             ui.write(_(b'using raw connection to peer\n'))
  4698             peer = None
  4656             peer = None
  4699         elif opts[b'peer']:
  4657         elif opts[b'peer']:
  4700             raise error.Abort(
  4658             raise error.Abort(
  4701                 _(b'--peer %s not supported with HTTP peers') % opts[b'peer']
  4659                 _(b'--peer %s not supported with HTTP peers') % opts[b'peer']
  4772                     )
  4730                     )
  4773             else:
  4731             else:
  4774                 with peer.commandexecutor() as e:
  4732                 with peer.commandexecutor() as e:
  4775                     res = e.callcommand(command, args).result()
  4733                     res = e.callcommand(command, args).result()
  4776 
  4734 
  4777                 if isinstance(res, wireprotov2peer.commandresponse):
  4735                 ui.status(
  4778                     val = res.objects()
  4736                     _(b'response: %s\n')
  4779                     ui.status(
  4737                     % stringutil.pprint(res, bprefix=True, indent=2)
  4780                         _(b'response: %s\n')
  4738                 )
  4781                         % stringutil.pprint(val, bprefix=True, indent=2)
       
  4782                     )
       
  4783                 else:
       
  4784                     ui.status(
       
  4785                         _(b'response: %s\n')
       
  4786                         % stringutil.pprint(res, bprefix=True, indent=2)
       
  4787                     )
       
  4788 
  4739 
  4789         elif action == b'batchbegin':
  4740         elif action == b'batchbegin':
  4790             if batchedcommands is not None:
  4741             if batchedcommands is not None:
  4791                 raise error.Abort(_(b'nested batchbegin not allowed'))
  4742                 raise error.Abort(_(b'nested batchbegin not allowed'))
  4792 
  4743