Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/debugcommands.py @ 36556:44dc34b8d17b
debugcommands: add debugserve command
`hg serve --stdio` requires the exact command argument form
`hg -R <path> serve --stdio` for security reasons. An upcoming
commit will need to start an SSH protocol server process with
custom settings.
This commit creates a `hg debugserve` command for starting servers
with custom options. There are no security restrictions and we can
add options here that aren't appropriate for built-in commands.
We currently only support starting an SSH protocol server using
the process's stdio file descriptors. The server supports logging
its I/O activity to a file descriptor number passed as a command
argument.
Differential Revision: https://phab.mercurial-scm.org/D2464
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 27 Feb 2018 15:47:44 -0800 |
parents | 6e90c59b6da1 |
children | 72e487851a53 |
comparison
equal
deleted
inserted
replaced
36555:7cc4a9b9732a | 36556:44dc34b8d17b |
---|---|
71 treediscovery, | 71 treediscovery, |
72 upgrade, | 72 upgrade, |
73 url as urlmod, | 73 url as urlmod, |
74 util, | 74 util, |
75 vfs as vfsmod, | 75 vfs as vfsmod, |
76 wireprotoserver, | |
76 ) | 77 ) |
77 | 78 |
78 release = lockmod.release | 79 release = lockmod.release |
79 | 80 |
80 command = registrar.command() | 81 command = registrar.command() |
2228 if not opts['show_revs']: | 2229 if not opts['show_revs']: |
2229 return | 2230 return |
2230 for c in revs: | 2231 for c in revs: |
2231 ui.write("%d\n" % c) | 2232 ui.write("%d\n" % c) |
2232 | 2233 |
2234 @command('debugserve', [ | |
2235 ('', 'sshstdio', False, _('run an SSH server bound to process handles')), | |
2236 ('', 'logiofd', '', _('file descriptor to log server I/O to')), | |
2237 ('', 'logiofile', '', _('file to log server I/O to')), | |
2238 ], '') | |
2239 def debugserve(ui, repo, **opts): | |
2240 """run a server with advanced settings | |
2241 | |
2242 This command is similar to :hg:`serve`. It exists partially as a | |
2243 workaround to the fact that ``hg serve --stdio`` must have specific | |
2244 arguments for security reasons. | |
2245 """ | |
2246 opts = pycompat.byteskwargs(opts) | |
2247 | |
2248 if not opts['sshstdio']: | |
2249 raise error.Abort(_('only --sshstdio is currently supported')) | |
2250 | |
2251 logfh = None | |
2252 | |
2253 if opts['logiofd'] and opts['logiofile']: | |
2254 raise error.Abort(_('cannot use both --logiofd and --logiofile')) | |
2255 | |
2256 if opts['logiofd']: | |
2257 # Line buffered because output is line based. | |
2258 logfh = os.fdopen(int(opts['logiofd']), 'ab', 1) | |
2259 elif opts['logiofile']: | |
2260 logfh = open(opts['logiofile'], 'ab', 1) | |
2261 | |
2262 s = wireprotoserver.sshserver(ui, repo, logfh=logfh) | |
2263 s.serve_forever() | |
2264 | |
2233 @command('debugsetparents', [], _('REV1 [REV2]')) | 2265 @command('debugsetparents', [], _('REV1 [REV2]')) |
2234 def debugsetparents(ui, repo, rev1, rev2=None): | 2266 def debugsetparents(ui, repo, rev1, rev2=None): |
2235 """manually set the parents of the current working directory | 2267 """manually set the parents of the current working directory |
2236 | 2268 |
2237 This is useful for writing repository conversion tools, but should | 2269 This is useful for writing repository conversion tools, but should |