Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/debugcommands.py @ 50978:36f116820853
debugserve: migrate `opts` to native kwargs
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Mon, 21 Aug 2023 17:41:01 -0400 |
parents | 98d1117dc904 |
children | e6ae6573b400 |
comparison
equal
deleted
inserted
replaced
50977:98d1117dc904 | 50978:36f116820853 |
---|---|
3488 | 3488 |
3489 This command is similar to :hg:`serve`. It exists partially as a | 3489 This command is similar to :hg:`serve`. It exists partially as a |
3490 workaround to the fact that ``hg serve --stdio`` must have specific | 3490 workaround to the fact that ``hg serve --stdio`` must have specific |
3491 arguments for security reasons. | 3491 arguments for security reasons. |
3492 """ | 3492 """ |
3493 opts = pycompat.byteskwargs(opts) | 3493 if not opts['sshstdio']: |
3494 | |
3495 if not opts[b'sshstdio']: | |
3496 raise error.Abort(_(b'only --sshstdio is currently supported')) | 3494 raise error.Abort(_(b'only --sshstdio is currently supported')) |
3497 | 3495 |
3498 logfh = None | 3496 logfh = None |
3499 | 3497 |
3500 if opts[b'logiofd'] and opts[b'logiofile']: | 3498 if opts['logiofd'] and opts['logiofile']: |
3501 raise error.Abort(_(b'cannot use both --logiofd and --logiofile')) | 3499 raise error.Abort(_(b'cannot use both --logiofd and --logiofile')) |
3502 | 3500 |
3503 if opts[b'logiofd']: | 3501 if opts['logiofd']: |
3504 # Ideally we would be line buffered. But line buffering in binary | 3502 # Ideally we would be line buffered. But line buffering in binary |
3505 # mode isn't supported and emits a warning in Python 3.8+. Disabling | 3503 # mode isn't supported and emits a warning in Python 3.8+. Disabling |
3506 # buffering could have performance impacts. But since this isn't | 3504 # buffering could have performance impacts. But since this isn't |
3507 # performance critical code, it should be fine. | 3505 # performance critical code, it should be fine. |
3508 try: | 3506 try: |
3509 logfh = os.fdopen(int(opts[b'logiofd']), 'ab', 0) | 3507 logfh = os.fdopen(int(opts['logiofd']), 'ab', 0) |
3510 except OSError as e: | 3508 except OSError as e: |
3511 if e.errno != errno.ESPIPE: | 3509 if e.errno != errno.ESPIPE: |
3512 raise | 3510 raise |
3513 # can't seek a pipe, so `ab` mode fails on py3 | 3511 # can't seek a pipe, so `ab` mode fails on py3 |
3514 logfh = os.fdopen(int(opts[b'logiofd']), 'wb', 0) | 3512 logfh = os.fdopen(int(opts['logiofd']), 'wb', 0) |
3515 elif opts[b'logiofile']: | 3513 elif opts['logiofile']: |
3516 logfh = open(opts[b'logiofile'], b'ab', 0) | 3514 logfh = open(opts['logiofile'], b'ab', 0) |
3517 | 3515 |
3518 s = wireprotoserver.sshserver(ui, repo, logfh=logfh) | 3516 s = wireprotoserver.sshserver(ui, repo, logfh=logfh) |
3519 s.serve_forever() | 3517 s.serve_forever() |
3520 | 3518 |
3521 | 3519 |