Mercurial > hg-stable
comparison mercurial/debugcommands.py @ 50984:fd6c748eb8a6
debugwireproto: migrate `opts` to native kwargs
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Mon, 21 Aug 2023 17:57:48 -0400 |
parents | a4d21089bec7 |
children | f636103c4d67 |
comparison
equal
deleted
inserted
replaced
50983:a4d21089bec7 | 50984:fd6c748eb8a6 |
---|---|
4481 ``payload`` represents the raw frame payload. If it begins with | 4481 ``payload`` represents the raw frame payload. If it begins with |
4482 ``cbor:``, the following string is evaluated as Python code and the | 4482 ``cbor:``, the following string is evaluated as Python code and the |
4483 resulting object is fed into a CBOR encoder. Otherwise it is interpreted | 4483 resulting object is fed into a CBOR encoder. Otherwise it is interpreted |
4484 as a Python byte string literal. | 4484 as a Python byte string literal. |
4485 """ | 4485 """ |
4486 opts = pycompat.byteskwargs(opts) | 4486 if opts['localssh'] and not repo: |
4487 | |
4488 if opts[b'localssh'] and not repo: | |
4489 raise error.Abort(_(b'--localssh requires a repository')) | 4487 raise error.Abort(_(b'--localssh requires a repository')) |
4490 | 4488 |
4491 if opts[b'peer'] and opts[b'peer'] not in ( | 4489 if opts['peer'] and opts['peer'] not in ( |
4492 b'raw', | 4490 b'raw', |
4493 b'ssh1', | 4491 b'ssh1', |
4494 ): | 4492 ): |
4495 raise error.Abort( | 4493 raise error.Abort( |
4496 _(b'invalid value for --peer'), | 4494 _(b'invalid value for --peer'), |
4497 hint=_(b'valid values are "raw" and "ssh1"'), | 4495 hint=_(b'valid values are "raw" and "ssh1"'), |
4498 ) | 4496 ) |
4499 | 4497 |
4500 if path and opts[b'localssh']: | 4498 if path and opts['localssh']: |
4501 raise error.Abort(_(b'cannot specify --localssh with an explicit path')) | 4499 raise error.Abort(_(b'cannot specify --localssh with an explicit path')) |
4502 | 4500 |
4503 if ui.interactive(): | 4501 if ui.interactive(): |
4504 ui.write(_(b'(waiting for commands on stdin)\n')) | 4502 ui.write(_(b'(waiting for commands on stdin)\n')) |
4505 | 4503 |
4509 stdin = None | 4507 stdin = None |
4510 stdout = None | 4508 stdout = None |
4511 stderr = None | 4509 stderr = None |
4512 opener = None | 4510 opener = None |
4513 | 4511 |
4514 if opts[b'localssh']: | 4512 if opts['localssh']: |
4515 # We start the SSH server in its own process so there is process | 4513 # We start the SSH server in its own process so there is process |
4516 # separation. This prevents a whole class of potential bugs around | 4514 # separation. This prevents a whole class of potential bugs around |
4517 # shared state from interfering with server operation. | 4515 # shared state from interfering with server operation. |
4518 args = procutil.hgcmd() + [ | 4516 args = procutil.hgcmd() + [ |
4519 b'-R', | 4517 b'-R', |
4532 stdin = proc.stdin | 4530 stdin = proc.stdin |
4533 stdout = proc.stdout | 4531 stdout = proc.stdout |
4534 stderr = proc.stderr | 4532 stderr = proc.stderr |
4535 | 4533 |
4536 # We turn the pipes into observers so we can log I/O. | 4534 # We turn the pipes into observers so we can log I/O. |
4537 if ui.verbose or opts[b'peer'] == b'raw': | 4535 if ui.verbose or opts['peer'] == b'raw': |
4538 stdin = util.makeloggingfileobject( | 4536 stdin = util.makeloggingfileobject( |
4539 ui, proc.stdin, b'i', logdata=True | 4537 ui, proc.stdin, b'i', logdata=True |
4540 ) | 4538 ) |
4541 stdout = util.makeloggingfileobject( | 4539 stdout = util.makeloggingfileobject( |
4542 ui, proc.stdout, b'o', logdata=True | 4540 ui, proc.stdout, b'o', logdata=True |
4546 ) | 4544 ) |
4547 | 4545 |
4548 # --localssh also implies the peer connection settings. | 4546 # --localssh also implies the peer connection settings. |
4549 | 4547 |
4550 url = b'ssh://localserver' | 4548 url = b'ssh://localserver' |
4551 autoreadstderr = not opts[b'noreadstderr'] | 4549 autoreadstderr = not opts['noreadstderr'] |
4552 | 4550 |
4553 if opts[b'peer'] == b'ssh1': | 4551 if opts['peer'] == b'ssh1': |
4554 ui.write(_(b'creating ssh peer for wire protocol version 1\n')) | 4552 ui.write(_(b'creating ssh peer for wire protocol version 1\n')) |
4555 peer = sshpeer.sshv1peer( | 4553 peer = sshpeer.sshv1peer( |
4556 ui, | 4554 ui, |
4557 url, | 4555 url, |
4558 proc, | 4556 proc, |
4560 stdout, | 4558 stdout, |
4561 stderr, | 4559 stderr, |
4562 None, | 4560 None, |
4563 autoreadstderr=autoreadstderr, | 4561 autoreadstderr=autoreadstderr, |
4564 ) | 4562 ) |
4565 elif opts[b'peer'] == b'raw': | 4563 elif opts['peer'] == b'raw': |
4566 ui.write(_(b'using raw connection to peer\n')) | 4564 ui.write(_(b'using raw connection to peer\n')) |
4567 peer = None | 4565 peer = None |
4568 else: | 4566 else: |
4569 ui.write(_(b'creating ssh peer from handshake results\n')) | 4567 ui.write(_(b'creating ssh peer from handshake results\n')) |
4570 peer = sshpeer._make_peer( | 4568 peer = sshpeer._make_peer( |
4607 openerargs['loggingopts']['logdataapis'] = True | 4605 openerargs['loggingopts']['logdataapis'] = True |
4608 | 4606 |
4609 # Don't send default headers when in raw mode. This allows us to | 4607 # Don't send default headers when in raw mode. This allows us to |
4610 # bypass most of the behavior of our URL handling code so we can | 4608 # bypass most of the behavior of our URL handling code so we can |
4611 # have near complete control over what's sent on the wire. | 4609 # have near complete control over what's sent on the wire. |
4612 if opts[b'peer'] == b'raw': | 4610 if opts['peer'] == b'raw': |
4613 openerargs['sendaccept'] = False | 4611 openerargs['sendaccept'] = False |
4614 | 4612 |
4615 opener = urlmod.opener(ui, authinfo, **openerargs) | 4613 opener = urlmod.opener(ui, authinfo, **openerargs) |
4616 | 4614 |
4617 if opts[b'peer'] == b'raw': | 4615 if opts['peer'] == b'raw': |
4618 ui.write(_(b'using raw connection to peer\n')) | 4616 ui.write(_(b'using raw connection to peer\n')) |
4619 peer = None | 4617 peer = None |
4620 elif opts[b'peer']: | 4618 elif opts['peer']: |
4621 raise error.Abort( | 4619 raise error.Abort( |
4622 _(b'--peer %s not supported with HTTP peers') % opts[b'peer'] | 4620 _(b'--peer %s not supported with HTTP peers') % opts['peer'] |
4623 ) | 4621 ) |
4624 else: | 4622 else: |
4625 peer_path = urlutil.try_path(ui, path) | 4623 peer_path = urlutil.try_path(ui, path) |
4626 peer = httppeer._make_peer(ui, peer_path, opener=opener) | 4624 peer = httppeer._make_peer(ui, peer_path, opener=opener) |
4627 | 4625 |